I'm trying to use the date command to get the previous month. When I run it on the 31 of may, it returns may 1, I was expecting something in april. Is there better way to do this ?
> date --version
date (GNU sh-utils) 2.0
Written by David MacKenzie.
Copyright (C) 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> date
Fri May 31 13:29:08 EDT 2013
> date --date='last month'
Wed May 1 13:29:15 EDT 2013
per comment from #fvu I tried this :
> date --date='first day last month'
Thu May 2 14:00:43 EDT 2013
> date --date='first day next month'
Tue Jul 2 14:00:52 EDT 2013
which didn't quite work. this did though :
>date --date='last day last month'
Tue Apr 30 14:06:28 EDT 2013
guess I need the definition of month
"last month" is meant to be 30 days ago, not the previous month, I believe.
date --date="$(date +%Y-%m-15) -1 month"
is the info example given to detect the previous month because -1 month is the same as -30 days
Related
I have been looking high and low and so far have seen no options via the code or anything else that seems to even come close to what i am asking. My request is simple enough. Typically when we want to display in a month grid view the month of September 2019 we expect the start of this month to be 9/1/2019 and the end to be 9/30/2019 with anything before or after to be considered other month.
However, I need for my calendar to have a different date range for the month of September 2019. This is so that it aligns with how we manage months. With the exception of the month of October all other months of the year are modified for different date range.
January = 01/01 to 01/30
February = 01/31 to 03/01
March = 03/02 to 03/31
April = 04/01 to 05/01
May = 05/02 to 06/01
June = 06/02 to 07/01
July = 07/02 to 07/31
August = 08/01 to 08/30
September = 08/31 to 09/30
October = 10/01 to 10/31
November = 11/01 to 12/01
December = 12/02 to 12/31
In many cases I do not need to make many adjustments (just some add/remove "fc-other-month" class, as the previous months ending dates are also visible (if using the 6 week enabled flag, which is also set by default), however, in September 2019, 09/01 is on a Sunday of the first week meaning that the previous week that would include 8/31 is not rendered.
I can explore a "brute force" type method of checking for this condition and then prepending another row on top of week 1 with the additional dates needed but I have to believe that there is a simple method where i can simply state the months start and end date range.
I need help with this scenario:
1) Currently it is summer time. I need to create a time interval for June 9 Monday 6 PM - 7 PM EDT and every week after that until end of 2018. This interval will be for students to schedule appointments with a tutor. The client right now sends that as a request for creating start time at June 9 Mondays 2 PM UTC. (EDT is -4 hours offset) The server creates a start time in db for June 9 2 PM UTC and adds 7 days worth of milliseconds to create recurring
^ this causes an issue because of DST. Let's say it is right now November 5th (which is after daylights saving change). The DB still has Nov 5, 2 PM UTC saved as value. But because my timezone changed, instead of offsetting by 4 hours like I did on June, I offset by 5 hours. So the correct start time is "6 PM session in my timezone" becomes "7 PM my timezone". this is the error
the solution is either of one of two (or combination of both):
1) instead of adding 7 days worth of milisecond, you add 1 week worth of miliseconds depending on the user's timezone Currently, there's no way to extract a person's timezone based on utc offset (-400, which is right now in east coast USA, is also applicable to Canada, Carribeans, South America etc. We need to save a user's timezone as a string, rather than UTC offset count. There is an international standard for timezones)
2) ?? something else
I have a few UNIX timestamps that I've been converting back and forth, and I notice that the last number of the timestamp would change without causing any difference in the date.
For example, if you convert this number to normal date:
1452120848 > 6-1-16 17:54
But if you convert it back:
6-1-16 17:54 > 1452120840
As you can see the last number was changed to a zero. I tried some of the online converters and discovered that the last number could be any number and the date wouldn't change. What does it mean?
The unix time is the time in seconds since 1970.
You don't convert the seconds part of your date, thus it's 'lost' - your numbers may differ by up to 60.
The timestamp of 1452120848 is actually: Wed Jan 6 22:54:08 2016
So you're missing 8 seconds.
The UNIX timestamp gives you the seconds since 1st January 1970 00.00.00 UTC. Since this is seconds and you are just printing up to minutes, the difference is not shown.
However, they are not the same date:
$ date -d#1452120848
Wed Jan 6 23:54:08 CET 2016
$ date -d#1452120840
Wed Jan 6 23:54:00 CET 2016
$datetime = new DateTime('0000-00-00 00:00:00');
$date_string = $datetime->format('Y-m-d H:i:s');//-0001-11-30 00:00:00
date gets turned from 0000-00-00 00:00:00 to -0001-11-30 00:00:00
this is obviously wrong, why does this happen, how to fix it?
Should at least return false.
info:
PHP Version 5.2.13-0.dotdeb.1
Linux 2.6.26-2-openvz-amd64 #1 SMP Thu Nov 25 05:14:47 UTC 2010 x86_64
It's sort of correct by definition:
the zero-th day as opposed to the first yields a (hypothetical) minus one day
the zero-th month as opposed to the first yields a (hypothetical) minus one month
Take the (hypothetical) 1st of Jan in the year 0, subtract a month -> 1st of Dec in the year -1.
Subtract a day -> 30th of Nov in the year -1
Alternatively, they could have chosen to fix up the day first, then it'd go like:
1 Jan minus 1d -> 31st of Dec -0001, minus 1mo -> 30th of Nov -0001
The formatter obviously does the bound check to only produce valid dates. (For some definition of ``valid'')
I am working in Excel 2007. My preference would be to do this without VBA. I am trying to count backwards a number of months starting from a given date. For example:
Start Date: July, 2010
Countdown: 12 months
Should result in:
Jun 2010
May 2010
Apr 2010
Mar 2010
Feb 2010
Jan 2010
Dec 2009
Nov 2009
Oct 2009
Sep 2009
Aug 2009
Jul 2009
So the seed month is month 0 and the countdown period can vary. I would like the month/year combination for display purposes but I also need the calculated value (ie, seed month is 0, next previous month is -1, etc) for calculations.
Any advice/help would be most appreciated!
It's relatively simple. For example, in cell A1, put "July 2010". In B1, put =DATE(YEAR(A1),MONTH(A1)-1,DAY(A1)) and in C1 put either =DATE(YEAR(A1),MONTH(A1)-2,DAY(A1)) or =DATE(YEAR(B1),MONTH(B1)-1,DAY(B1)) and so on.
If you're looking for a for/each type of statement with the number of months in the countdown, you'll need to go to VBA. Otherwise, you can prepopulate a range of cells with code like the above (You can start it with an if statement if the countdown cell has nothing, to display nothing).