I have seen this question in many formats, including C/C+ and Javascript. I've also seen this question in it's converse form... . But, just suppose you already have a specific date. Let's say, for example, 2014-01-04 and I would like to calculate a date ($diff) three WORKING days before that excluding any weekends or holidays. A direct subtraction of three days would result in 2014-01-01, so we know that won't work. So, I subtract another day and get 2013-12-31 - again, no good. Another attempt gives us 2013-12-30. Finally, we have three ACTUAL WORKING DAYS between the two dates!! But, let's just say that as it will in 2014, 2013-12-30 falls on a Sunday.... man, oh man - shafted again! Well, I think you get my point here. How in the world do I get the results I want?
3855
I need a method for adding "business days" in PHP. For example, Friday 12/5 + 3 business days = Wednesday 12/10.  At a minimum I need the code to understand weekends, but ideally it should account for US federal holidays as well. I'm sure I could come up with a solution by brute force if necessary, but I'm hoping there's a more elegant approach out there. Anyone?  Thanks.
67697
I have tried using =TEXT(Today,"mm-dd-yyyy hh:mm:ss") but that only returns the 5/5/55 00:00:00, it won't give the time. How do I get both the date and time with a calculated formula?
2357
I have two dates of the form:  Start Date: 2007-03-24  End Date: 2009-06-26   Now I need to find the difference between these two in the following form:  2 years, 3 months and 2 days   How can I do this in PHP?
38765
Is there any tool in Solaris UNIX (so no GNU tool available) to subtract dates? I know that in Linux we have gawk that can subtract one date from another. But in Solaris the maximum we have is nawk (improved awk) which cannot perform date calculations. Also I cannot use perl.  Is there any way to do date calculations like 20100909 - 20001010?  UPDATE: Is bc able to perform dates calculations?
36605
Looking at , I see "asked yesterday" (which I really hate; I'd like to see an exact time specification rather than this vague one, especially in the list of questions). But it was not asked yesterday! When I hover over it to show the exact time, it shows it was actually the day before yesterday!  This snapshot was taken at 2012-03-31 15:00 UTC (plus or minus a few minutes):    Whatever different opinions you may have on the implementation, yesterday is a word with a certain meaning. Redefining it is not a good idea. At least rephrase this as "1 day ago" or something.
1510
I'm working with a date in this format: yyyy-mm-dd.  How can I increment this date by one day?
20616
I need to do date arithmetic in Unix shell scripts that I use to control the execution of third party programs.   I'm using a function to increment a day and another to decrement:   IncrementaDia(){ echo $1 | awk ' BEGIN {         diasDelMes[1] = 31         diasDelMes[2] = 28         diasDelMes[3] = 31         diasDelMes[4] = 30         diasDelMes[5] = 31         diasDelMes[6] = 30         diasDelMes[7] = 31         diasDelMes[8] = 31         diasDelMes[9] = 30         diasDelMes[10] = 31         diasDelMes[11] = 30         diasDelMes[12] = 31 } {         anio=substr($1,1,4)         mes=substr($1,5,2)         dia=substr($1,7,2)          if((anio % 4 == 0 &amp;&amp; anio % 100 != 0) || anio % 400 == 0)         {                 diasDelMes[2] = 29;         }          if( dia == diasDelMes[int(mes)] ) {                 if( int(mes) == 12 ) {                         anio = anio + 1                         mes = 1                         dia = 1                 } else {                         mes = mes + 1                         dia = 1                 }         } else {                 dia = dia + 1         } } END {         printf("%04d%02d%02d", anio, mes, dia) } ' }  if [ $# -eq 1 ]; then         tomorrow=$1 else         today=$(date +"%Y%m%d")         tomorrow=$(IncrementaDia $hoy) fi   but now I need to do more complex arithmetic.   What it's the best and more compatible way to do this?
492
I have a web page with three dropdowns for day, month and year. If I use the JavaScript Date constructor that takes numbers, then I get a Date object for my current timezone:  new Date(xiYear, xiMonth, xiDate)   Give the correct date, but it thinks that date is GMT+01:00 due to daylight savings time.  The problem here is that I then pass this Date to an Ajax method and when the date is deserialised on the server it has been converted to GMT and so lost an hour which moves the day back by one. Now I could just pass the day, month, and year individually into the Ajax method, but it seems that there ought to be a better way.  The accepted answer pointed me in the right direction, however just using setUTCHours() by itself changed:  Apr 5th 00:00 GMT+01:00    to  Apr 4th 23:00 GMT+01:00   I then also had to set the UTC date, month and year to end up with  Apr 5th 01:00 GMT+01:00   which is what I wanted.
1661
I find it funny that Java (or the java.util library) does not have a built-in function to calculate difference in dates. I want to subtract one date from another to get the elapsed time between them. What is the best way to do this?   I know the simple way is to take the difference of the time in milliseconds and then convert that into days. However, I wanted to know if this works in all cases (with daylight saving, etc.).
32181
I want to schedule my script for last Saturday of every month. I have come up with the below:  45 23 22-28 * *  test $(date +\%u) -eq 6 &amp;&amp; echo "4th Saturday"  &amp;&amp; sh  /folder/script.sh    Is this correct or I need to change it? I can't test it right now as it will be invoked only on last saturday. Please advise.  I have the below for last sunday of every month but i can't understand much of it. The first part gives 24 which is sunday and after -eq gives 7 which i don't know what it means:  00 17  * * 0 [ $(cal -s | tail -2 | awk '{print $1}') -eq $(date | awk '{print $3}') ] &amp;&amp; /folder/script.sh   Can i modify the above to get last saturday?  With Romeo's help I was help to come up with the below answer:  00 17 * * 6 [ $(cal -s | tail -2 | awk '{print $7}') -eq $(date | awk '{print $3}') ] &amp;&amp; /folder/script.sh
14368
If I have two dates (ex. '8/18/2008' and '9/26/2008'), what is the best way to get the number of days between these two dates?
75387
Suppose I have a particular date stored in a variable date_m. I want ((date_m)-25) date.   For example: I have 15/09/2014 stored in my variable , then I want 21/08/2014 returned if I subtract 25 from the date stored in variable.
116559
I need to decrement a Javascript date by 1 day, so that it rolls back across months/years correctly.  That is, if I have a date of 'Today', I want to get the date for 'Yesterday'.  It always seems to take more code than necessary when I do this, so I'm wondering if there's any simpler way.    What's the simplest way of doing this?  [Edit: Just to avoid confusion in an answer below, this is a JavaScript question, not a Java one.]
76394
I need to do a date comparison in Mysql without taking into account the time component i.e. i need to convert '2008-11-05 14:30:00' to '2008-11-05'  Currently i am doing this:  SELECT from_days(to_days(my_date))   Is there a proper way of doing this?
92403
I know that you can use daysBetween() for two Date objects, but what would I use to calculate the elapse time in seconds between two DateTime objects?
23276
I have set up a Google spreadsheet for managing projects and due dates, and I need to apply the following formatting to a column of dates, but I'm not sure how:   Dates more than 7 days from today: Black   Dates less than or equal to 7 days from today: Green   Dates before today (late projects): Red   , but this doesn't actually do what it needs to do. It turns dates that are only 1 week LATE orange. It does not change dates that are one week AWAY orange. So this isn't working... unless I'm missing something.
2199
I use a datepicker for choosing an appointment day.  I already set the date range to be only for the next month.  That works fine.  I want to exclude Saturdays and Sundays from the available choices.  Can this be done?  If so, how?