There's a lot of corner cases. We had Feb 29th this year for example; Feb 29th minus 1 year gives you march 1st. Replicating GNU date's most obvious features was (slightly) easier than I thought, as it did pretty much what I did -- calculate the difference without trying to be too intelligent about it. It's intelligent enough to subtract the month number rather than a time offset of some sort, but doesn't correct the number of days after.
It's difficult to guess the user's intention for date math, so it's hard to call this a bug exactly. Rather it's just our convoluted, irrational calendar system and not-a-nice-round-number orbital period coming back to bite us once again.
If you wanted it to snap to months in that manner, try feeding it the first of the month and subtracting that, that should always work.*
*within timescales of 30 years. Ugh, dates are weird.
Last edited by Corona688; 08-31-2016 at 01:25 PM..
hi,
how do i get the last day of the current date or a given date using unix.
for e.g. if i run the command/script on 1st feb 2002 i should get 28 th feb 2002.
thanks !!
AnkuR. (3 Replies)
hi guys, i've got a simple one..
date_time="`date '+%Y-%m-%d %H:%M:%S'`" gives me the system's date and time...
which my script will use this variable to run the data on this date...
my question is... if now, i want to run the script for data's that are like 6 months back...
how can i... (1 Reply)
I know there are some posts on getting the time with milliseconds included and I realize unix may not be the best on this.
I have seem some posts where its advised to install the GNU date.
Any one know where I can download this as I am struggling to find it.
Alternatively - if you have... (5 Replies)
How could I get a date's day of the week (ie Sunday) without using the date -d command?
So if a date was specified, it would give me the day of the week.
The date -d command looks something like this
date -d $inputdate | cut -c 1-3
the only problem with that statement is that it won't... (2 Replies)
I have been out of the UNIX World for a number of years and none of my reference books seem to be helping e with this seemingly simple question. How can I manipulate the below command to reflect the previous day and not the current date?
the command is:
elm -s “SAP prs for `date... (4 Replies)
Should work in any shell, but requires GNU date, although GNU date seems only to be happy for input dates between 1902 and 2037, inclusive (49673 days).
Assume $a and $b hold two dates, e.g.
set a=2010-03-27
set b=2010-04-04
Marginally faster:
iterator: seq -f "$a +%1.0f days" 1 50000 |... (0 Replies)
Hello everybody,
Currently I'm learning how to build projects (C programming) with GNU make. I have a problem with one Makefile and I would appreciate if you could kindly give me a hand. Here is the environment:
OS: Redhat linux 5
compiler: gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)... (2 Replies)
Dear all,
This should be simple but I cannot figure it out despite reading all the man pages. Could someone please help me translate this code (GNU date) to one that can be read by BSD date?:
myDate=$(date -d "$h -$l days" +%Y/%m/%d),
where h is a variable of the form DD/MM/YYYY, and l is... (3 Replies)
It's easy as pie to get the date minus one day on opensolaris:
date -d "-1 day" +"%Y%m%d"run this command on our crappy Solaris 10 machines however (which I'm guessing doesn't have GNU date running on it) and you get:
date: illegal option -- d
date: illegal option -- 1
date: illegal option --... (5 Replies)
So as I write this today is two days after the clocks go back here in the UK. I have a script that worked last week. Yesterday it developed a bug. I eventually found the culprit is Gnu Date.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS... (10 Replies)
Discussion started by: apmcd47
10 Replies
LEARN ABOUT SUSE
image::exiftool::shift
Image::ExifTool::Shift(3) User Contributed Perl Documentation Image::ExifTool::Shift(3)NAME
Image::ExifTool::Shift.pl - ExifTool time shifting routines
DESCRIPTION
This module contains routines used by ExifTool to shift date and time values.
DETAILS
Time shifts are applied to standard EXIF-formatted date/time values (ie. "2005:03:14 18:55:00"). Date-only and time-only values may also
be shifted, and an optional timezone (ie. "-05:00") is also supported. Here are some general rules and examples to explain how shift
strings are interpreted:
Date-only values are shifted using the following formats:
'Y:M:D' - shift date by 'Y' years, 'M' months and 'D' days
'M:D' - shift months and days only
'D' - shift specified number of days
Time-only values are shifted using the following formats:
'h:m:s' - shift time by 'h' hours, 'm' minutes and 's' seconds
'h:m' - shift hours and minutes only
'h' - shift specified number of hours
Timezone shifts are specified in the following formats:
'+h:m' - shift timezone by 'h' hours and 'm' minutes
'-h:m' - negative shift of timezone hours and minutes
'+h' - shift timezone hours only
'-h' - negative shift of timezone hours only
A valid shift value consists of one or two arguments, separated by a space. If only one is provided, it is assumed to be a time shift when
applied to a time-only or a date/time value, or a date shift when applied to a date-only value. For example:
'7' - shift by 1 hour if applied to a time or date/time
value, or by one day if applied to a date value
'2:0' - shift 2 hours (time, date/time), or 2 months (date)
'5:0:0' - shift 5 hours (time, date/time), or 5 years (date)
'0:0:1' - shift 1 s (time, date/time), or 1 day (date)
If two arguments are given, the date shift is first, followed by the time shift:
'3:0:0 0' - shift date by 3 years
'0 15:30' - shift time by 15 hours and 30 minutes
'1:0:0 0:0:0+5:0' - shift date by 1 year and timezone by 5 hours
A date shift is simply ignored if applied to a time value or visa versa.
Numbers specified in shift fields may contain a decimal point:
'1.5' - 1 hour 30 minutes (time, date/time), or 1 day (date)
'2.5 0' - 2 days 12 hours (date/time), 12 hours (time) or
2 days (date)
And to save typing, a zero is assumed for any missing numbers:
'1::' - shift by 1 hour (time, date/time) or 1 year (date)
'26:: 0' - shift date by 26 years
'+:30 - shift timezone by 30 minutes
Below are some specific examples applied to real date and/or time values ('Dir' is the applied shift direction: '+' is positive, '-' is
negative):
Original Value Shift Dir Shifted Value
------------------------------- ---------------------
'20:30:00' '5' + '01:30:00'
'2005:01:27' '5' + '2005:02:01'
'11:54:00' '2.5 0' - '23:54:00'
'2005:11:02' '2.5 0' - '2005:10:31'
'2005:11:02 11:54:00' '2.5 0' - '2005:10:30 23:54:00'
'2004:02:28 08:00:00' '1 1.3' + '2004:02:29 09:18:00'
'07:00:00' '-5' + '07:00:00'
'07:00:00+01:00' '-5' + '07:00:00-04:00'
'07:00:00Z' '+2:30' - '07:00:00-02:30'
'1970:01:01' '35::' + '2005:01:01'
'2005:01:01' '400' + '2006:02:05'
'10:00:00.00' '::1.33' + '09:59:58.67'
NOTES
The format of the original date/time value is not changed when the time shift is applied. This means that the length of the date/time
string will not change, and only the numbers in the string will be modified. The only exception to this rule is that a 'Z' timezone is
changed to '+00:00' notation if a timezone shift is applied. A timezone will not be added to the date/time string.
TRICKY
This module is perhaps more complicated than it needs to be because it is designed to be very flexible in the way time shifts are specified
and applied...
The ability to shift dates by Y years, M months, etc, is somewhat contradictory to the goal of maintaining a constant shift for all time
values when applying a batch shift. This is because shifting by 1 month can be equivalent to anything from 28 to 31 days, and 1 year can
be 365 or 366 days, depending on the starting date.
The inconsistency is handled by shifting the first tag found with the actual specified shift, then calculating the equivalent time
difference in seconds for this shift and applying this difference to subsequent tags in a batch conversion. So if it works as designed,
the behaviour should be both intuitive and mathematically correct, and the user shouldn't have to worry about details such as this (in
keeping with Perl's "do the right thing" philosophy).
AUTHOR
Copyright 2003-2010, Phil Harvey (phil at owl.phy.queensu.ca)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO Image::ExifTool(3pm)perl v5.12.1 2010-01-04 Image::ExifTool::Shift(3)