+ Reply to Thread
Results 1 to 13 of 13

How to assign dates and times to 'night' or 'day'?

  1. #1
    Registered User
    Join Date
    08-11-2014
    Location
    Suffolk
    MS-Off Ver
    07
    Posts
    6

    How to assign dates and times to 'night' or 'day'?

    Hello all,
    I'm hoping someone can help me.

    I have data going back to 2001, with dates and times recorded within the data set.
    What I'd really like to do is be able to create a formula which says, for example, 18:00 April 12th 2005 = DAY, or 23:00 October 30th 2006 = NIGHT.

    So, I'd like to assign dates and times to 'day' or 'night.'

    However, as I'd like this to be as accurate as I can, I'd also like to implement something which takes into account seasonality. So, for example, 9pm during the winter might be night time, but during the summer, may be day time.

    Is this possible?

    Thank you.

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to assign dates and times to 'night' or 'day'?

    Hi and welcome to the forum!

    Is the decision re which times are considered "night" and which are considered "day" in each season coming from you, or do you wish someone here at the forum to decide upon those definitions for you?

    If it's coming from you, could you please share them so that we can formulate the necessary solution?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    08-11-2014
    Location
    Suffolk
    MS-Off Ver
    07
    Posts
    6

    Re: How to assign dates and times to 'night' or 'day'?

    Hi there,
    The definitions would have to be based on historic records of sunrise and sunset in a particular area (in my case, southwest England).
    I can get hold of this information, for example, at a certain time on a certain date, it was past sunset (aka NIGHT). But I have over 27,000 rows of data I need to assign, so really can't do it manually.

    I hope that makes sense, and hope it addresses your question?

    Thank you.

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to assign dates and times to 'night' or 'day'?

    Still not sure I understand. Are you now saying that you want the degree of accuracy to be based on the sunrise/sunset times for each historical day? And not just an average for each season, which your first post seemed to suggest?

    Also, forgive me for my lack of knowledge on the subject, but from your description it would seem that having sunrise/sunset times for just a single year would not be sufficient. I wasn't aware that the sunset/sunrise times at a given location and at a given date in the year were that much different in 10,000BC than they are today. How big are those differences? Big enough to mean that you couldn't use a single year's worth of data and apply it to to all dates from all years?

    Either way, the only way you can realistically do this is to reference a table containing the sunrise/sunset times for each period in which you're interested. Once you've got that table, you can use a simple LOOKUP to get the required result for the dates/times of your choice.

    Regards

  5. #5
    Registered User
    Join Date
    08-11-2014
    Location
    Suffolk
    MS-Off Ver
    07
    Posts
    6

    Re: How to assign dates and times to 'night' or 'day'?

    Hi XOR LX, forgive my answer if it didn't answer your question fully.
    Intitially, yes, based on sunrise/sunset times for each historical day, but thinking about it from what you've said, I believe average for each season would suffice.
    Yes, you're quite right, I would need to obtain sunrise/sunset times per year too.

    So, hopefully if I find values for sunset/sunrise (averaged) per season and per year, and then apply a LOOKUP, that'll do the trick.

    Thank you for your help, it now seems simpler in my mind that how I initially feared!

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: How to assign dates and times to 'night' or 'day'?

    Short but useless answer, I'm sure this is possible. It is difficult to give specific suggestions for a generic question. Here's how I see the solution being developed:

    step 0) Determine input type. Are your data stored in Excel as date/time serials or as text strings? I don't work with dates and times in Excel much, so I don't know which will be easier. But I expect that it will be easiest to pick an "input date type" (if you will) and stick with that. This is a good introduction to how Excel handles dates and times as serial numbers that will help inform this decision: http://www.cpearson.com/Excel/datetime.htm#SerialDates
    step 1) Based on given date, determine sunrise/sunset times. Again, exactly how to do this depends on the exact format of your sunrise/sunset data. Is it a formula that you use to calculate sunrise/sunset, or is it more of a lookup table? If it is a formula, you will need to understand the formula well enough to get the needed calendar information from the raw data to put into the function and calculate sunrise/sunset. If it is more of a lookup table, you can import that lookup table and use Excel's lookup functions to return sunrise/sunset night/day times: http://office.microsoft.com/en-us/ex...188.aspx?CTT=1 (Vlookup is probably the most commonly used -- especially for beginners to Excel's lookup functions).
    step 2) Once we know the desired sunrise and sunset times, we can extract the time from the desired data point and compare it to the sunrise sunset times and determine if it is a "night" or "day" point.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to assign dates and times to 'night' or 'day'?

    You're welcome. And please come back if you need help with those lookups.

    By the way, I'm curious now: is it true that sunrise/sunset times for a given date/location differ much year-on-year?

    Regards

  8. #8
    Registered User
    Join Date
    08-11-2014
    Location
    Suffolk
    MS-Off Ver
    07
    Posts
    6

    Re: How to assign dates and times to 'night' or 'day'?

    Thank you both for your help, I think I'm now at the VLOOKUP stage.

    XOR XL, I think over a very long time period, perhaps yet. However on second thoughts for my data (just over a decade's worth), I think any deviation in the times will be insignificiant for what I'm after.

    I used a command in the 'R Project' software (not sure if anyone's familiar with it) to generate sunrise and sunset times for SW England, per month.

    For example, it gives me on the 1st Jan, sun rise is at 8.01 and sun set is at 16.12.

    I'm wondering whether there's a huge LOOKUP function I can type to apply to the whole data set, or whether it might be easier to tackle it in stages?

    Ideally I'd like to say 'if the month is january, between 8.01 and 16.12 = day and outside of those hours = night' and so on and so forth for the remaining 11 months...

    Forgive my excel lack of knowledge, it's been a long time since I've worked with formulas. Happy to read through the guides on here, but just wondering whether it can be done easy enough via one lookup command, or whether Excel gurus such as yourselves would recommend breaking it up?

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to assign dates and times to 'night' or 'day'?

    I tell you what: why don't you reply to this post when you've obtained the data you want, and hopefully organised it into a nice, simple table, and I'll help you write the necessary lookup formula to obtain your desired results, ok?

    Cheers

  10. #10
    Registered User
    Join Date
    08-11-2014
    Location
    Suffolk
    MS-Off Ver
    07
    Posts
    6

    Re: How to assign dates and times to 'night' or 'day'?

    Thank you for the kind offer, XLOR LX; greatly appreciated.

    Attached is an example of some of the data I'm using, with the sunset/sunrise times shown too. Hopefully it's in a suitable layout/format. The real data set has more data columns (but they're not really relevent for what we're doing here) and rows.

    Thank you.Example data.xlsx

  11. #11
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to assign dates and times to 'night' or 'day'?

    Ok, thanks.

    I notice that each of column A and B contains exactly the same date/time entry, but are just formatted differently (one to show date only, one to show time only), which is fine, though you need to bear in mind that the formula needs a slight tweak because of this, which it wouldn't if you had e.g. just the date in column A and just the time in column B.

    As it stands, you could use something like (in C2):

    =IF(MOD(B2,1)>INDEX($G$5:$G$16,MATCH(TEXT(A2,"mmm"),$E$5:$E$16,0)),"NIGHT","DAY")

    Copy down as required.

    Hope that helps.

    Cheers

  12. #12
    Registered User
    Join Date
    08-11-2014
    Location
    Suffolk
    MS-Off Ver
    07
    Posts
    6

    Re: How to assign dates and times to 'night' or 'day'?

    Thank youvery much, that seems to do the trick. I've noticed though, that it's telling me that 03:00 in January is DAY, when it should be night. I'll take another look at the formula. Thank you

  13. #13
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to assign dates and times to 'night' or 'day'?

    Apologies. Wasn't thinking clearly:

    =IF(AND(MOD(B2,1)>=INDEX($F$5:$F$16,MATCH(TEXT(A2,"mmm"),$E$5:$E$16,0)),MOD(B2,1)<=INDEX($G$5:$G$16,MATCH(TEXT(A2,"mmm"),$E$5:$E$16,0))),"DAY","NIGHT")

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Calculatuing Night Differential from start and end times that pass midnight
    By D J in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-16-2013, 11:35 AM
  2. Replies: 4
    Last Post: 09-21-2012, 12:58 AM
  3. [SOLVED] Adding dates and times to dates and times
    By JohnDowds in forum Excel General
    Replies: 2
    Last Post: 06-10-2012, 12:22 AM
  4. finding night hours (0-day,1-night) between ranges of data
    By sensation in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-09-2012, 09:08 AM
  5. Select certain cells in matrix to assign a 0-1 or 1-0 dyad 10,000 times
    By LaraCat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-02-2010, 08:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1