Comparing Date, Time or TimeStamp is tricky thing in Linux. This is how you can achieve this -
By converting date to Seconds
$ date +%s
the above command will current time in seconds since 1970-01-01 00:00:00 UTC
if you have time in string form you can use below command to convert them like -
$ date -d "$ts" +%s #where ts is containing the date or timestamp
i.e -
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ts1="2008-02-13 10:48:58.502075" | |
date -d "$ts1" +%s | |
1202928538 | |
# so for comparison of timestamps -- | |
ts1="2008-02-13 10:48:58.502075" | |
ts2="2008-12-15 16:00:00.000000" | |
if [ $( date -d "$ts1" +%s ) -gt $( date -d "$ts2" +%s ) ]; then echo $ts1; else echo $ts2; fi | |
2008-12-15 16:00:00.000000 |
Like the Facebook Page & join Group
https://www.facebook.com/DataStage4you
https://www.facebook.com/groups/DataStage4you
https://twitter.com/datastage4you
For WHATSAPP group , drop a msg to 91-88-00-906098
No comments :
Post a Comment