LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-08-2016, 08:45 AM   #1
rajivswe.2k7
LQ Newbie
 
Registered: Apr 2013
Posts: 15

Rep: Reputation: Disabled
date:- date command giving different results.


Hi All,

I am new to this Site. My task would be to suppress the hours, minutes, seconds from date which is in epoch format and the value is dynamical.

Below are my steps i have tried and i am getting different results.

For example I have used ‘20160101 01:04:01’ value and converted into epoch time.
[ ~]$ date -d "20160101 01:04:01" +%s
1451628241
I have calculated the number of days from the epoch time using the below math
[~]$ echo "1451628241/86400"|bc
16801
Then, I have multiplied with 86400 with the results.
[~]$ echo "16801*86400"|bc
1451606400
I have converted the epoch time and I would expect the output as ‘20160101 00:00:00’.But I am getting the bellow output.
[~]$ date -d @1451606400 "+%Y%m%d %H:%M:%S"
20151231 19:00:00

Please advice.
 
Old 08-08-2016, 09:27 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,401

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
What's wrong with just using
Code:
date -d @${THEEPOCHSECONDS} "+%Y%m%d"
to return just the parts you need?
 
1 members found this post helpful.
Old 08-08-2016, 09:51 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,508

Rep: Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102
You need to watch time zones. Epoch is in UTC, when you convert to an integer multiple of 86400 you're converting to 00:00 UT, and apparently the local time offset where you live is -5 hours. Add the "-u" flag in your last command to print out that epoch time in UTC and you'll see it's what you expect.
 
2 members found this post helpful.
Old 08-08-2016, 10:07 AM   #4
rajivswe.2k7
LQ Newbie
 
Registered: Apr 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thank you TenTenths. I have read through the "How To Ask A Question" link and i understand the points listed. I will make sure that i will follow the instructions in future.(I would like to understand the actual output if the results with the seconds thats is the reason i haven't tried '"+%Y%m%d"' format)
 
Old 08-08-2016, 10:11 AM   #5
rajivswe.2k7
LQ Newbie
 
Registered: Apr 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thank you suicidaleggroll. It works for me.
 
Old 08-10-2016, 03:56 AM   #6
rhubarbdog
Member
 
Registered: Apr 2015
Location: Yorkshire, England
Distribution: Linux Mint
Posts: 53

Rep: Reputation: Disabled
what about leap seconds
 
Old 08-10-2016, 08:29 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,508

Rep: Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102
What about them?
Leap seconds only need to be taken into account the day surrounding their occurrence or when converting to/from GPS time.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problems using mktime() to calculate diff. between date on c++ (inconstant results) Lobinho Programming 4 07-28-2010 07:53 AM
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 07:37 AM
PHP date() results off by an hour? win32sux Programming 4 02-18-2009 06:51 AM
Setting system date and time affecting the clock and date on BIOS satimis Ubuntu 7 09-21-2007 08:02 AM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 08:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration