Start 6/7/2018 13:00 - End 7/14/2018 10:00 = Unix Time 3186000
The above is 35 days and 23 hours, converted to seconds is 3106800
So the manual conversion is 22 minutes different (less) from converting the date/times to Unix Time Stamps and subtracting.
Why?
Related
I have separate date and time fields for an event and the data entry of that event. How do I determine the hours between the event and the data entry?
The time field is a string in standard time which I converted to a military time time field using a formula.
date is written in mm/dd/yyyy format and time is in standard time hh:mm am/pm which I've converted to HH:MM military time.
If an event happened at 12:10 pm on 12/3/2016 but it was entered at 1:25 pm on 12/5/2016, I want to see 49 Hours and 15 Minutes in my final field
DateDiff is just what you need. Something like:
DateDiff("h", DateTime({StartDate},{StartTime}), DateTime({EndDate},{EndTime}))
& " Hours and " &
DateDiff("n", DateTime({StartDate},{StartTime}), DateTime({EndDate},{EndTime})) Mod 60
& " Minutes"
This will retrieve the difference between your two dateTimes twice - Once in hours, once in minutes. Perform Mod 60 on the minutes section to get only the remainder minutes after subtracting 60 minutes for each hour.
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
I need to predict the next run of a daily job. For example, if my job runs everyday at 1:00:00 am, and my sysdate is Nov 7 11:20:00 am, then my next run will be at Nov 8 1:00:00 am
The below logic helps me to achieve the desired results. However, when i convert the date after adding no. days to the start date, unix considers the daylight saving and converts from PDT timezone to PST timezone and gives me a time lag of 1 hour. Instead of getting Nov 8 1:00:00 am, I am getting Nov 8 00:00:00 am as output.
I want to derive date without the day light savings. Can someone help me achieve this logic in UNIX?
CURR_DATE=`date "+%s"`
START_DATE=`date -d "19OCT2014 01:00:00" "+%s"` #start date when the job was run first
diff_quo=$(((($CURR_DATE - $START_DATE) / (86400))))
diff_quo=$(($diff_quo * 86400))
new_datetime=$(($START_DATE + $diff_quo + 86400 ))
DERIVED_DATE=`date -d"#$new_datetime" "+%b %d %H:%M:%S"`
Thanks,
Ekata
my_current_epoch=15684 equivalent time stamp is Thu, 01 Jan 1970 04:21:24
last_password_reset_epoch_time=15547 equivalent time stamp is Thu, 01 Jan 1970 04:19:07
I am not able to understand how difference of these two will give the days since last password reset.
As per my understanding epoch time is denoted in seconds that has elapsed since Jan 1,1970
Can someone please help me understanding this.
man 5 shadow on a Linux box says:
The date of the last password change is given as the number of days since Jan 1, 1970. The password may not
be changed again until the proper number of days have passed, and must be changed after the maximum number
of days. If the minimum number of days required is greater than the maximum number of day allowed, this
password may not be changed by the user.
So, you can find out to within 24 hours when a password was changed by multiplying the value from /etc/shadow by 86400 (the number of seconds in a day — but you didn't need me to tell you that, did you?).
For the values given (bc to the rescue):
15684*86400 = 1355097600
15547*86400 = 1343260800
And:
$ timestamp -u 1355097600 1343260800
1355097600 = Mon Dec 10 00:00:00 2012
1343260800 = Thu Jul 26 00:00:00 2012
$
Timestamp is my program; modern versions of date can handle this too. The -u means 'report in UTC (aka GMT)' rather than in my time zone.
"epoch" value in /etc/shadow = 15684
the seconds in 24 hours (because normally "epoch" value shows in seconds but for some reason (to make compact view, maybe) in /etc/shadow file "epoch" value displays in days, not in seconds) = 24 * 60 * 60 = 86400
And by multipliying these two numbers: 15684 (days) x 86400 (seconds per day); we will get the number 1355097600.
Afterwards, either using Epoch Converter by copy/paste the final result, you can get the date, or
just use date --date #$(( 15684 * 86400 )) command in cli
Looking for help in unix to get the following date stamps using unix date:
today at 12:00am
12:00am - 15 days ago
12:00am - 30 days ago
in Unix epoch time? (1300295838)
Today at 12:
mydate="`date +%D` 12:00"
To do date arithmetic:
date -d "$mydate 15 days ago"
To get epoch time:
date +%s
To put together in oneliner:
date -d "`date +%D` 12:00 15 days ago" +%s
to calculate the date for YESTERDAY:
time is the current time in seconds(the number of seconds in a day)
dateYYYYMMDD=`perl -MPOSIX -le 'print strftime "%Y%m%d", localtime(time-60*60*24);'`
time +/- calculate the seconds for your desired date after or before the current time in seconds.
You can use date -d on the shell to have it display the time you specify, not the current time. For time formatting characters, see: http://unixhelp.ed.ac.uk/CGI/man-cgi?date
You can use a perl library such as DateTime to do this quite easily.
For example, the following code creates a new date my subtracting 15 days from today and then calls the epoch function:
use DateTime;
my $dt = DateTime->now
->subtract(days => 15)
->set_hour(0)
->set_minute(0)
->set_second(0);
print $dt->epoch(),"\n";