473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

days since epoch

hi
how can i get the number of days since epoch using the time module?
or do i have to manually do the arithmetic?
thanks

Feb 17 '06 #1
3 18821
<ei***********@yahoo.com> wrote:
hi
how can i get the number of days since epoch using the time module?
or do i have to manually do the arithmetic?


Try the datetime module -- better suited to computing days, than the
time module, IMHO.
Alex
Feb 17 '06 #2
As suggested by Alex the datetime module makes this easy:

py> import datetime
py> epoch = datetime.datetime.utcfromtimestamp(0)
py> print epoch
1970-01-01 00:00:00
py> today = datetime.datetime.today()
py> d = today - epoch
py> print d
13196 days, 9:50:44.266200
py> print d.days # timedelta object
13196

Feb 17 '06 #3
The datetime module is usually more convenient for date/time
arithmetic. However in your particular case, you may find the
time.time() function convenient. It returns the number of seconds
since the epoch. To get the number of days divide the number of
seconds by 86400.

Feb 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: vertigo | last post by:
Hello How can i count how many there were days since 1 Jan 1970 ? Thanx Michal
7
by: Stu | last post by:
Is there a simple function call within "C" that I can use to convert number of seconds (keep in mind this may be a type longlong and has to work on UNIX and NT) into Days, months, Hours, Minutes...
11
by: Laery | last post by:
Hi, I'm currently adding a new module to an old borland C3.1 application (dos). And I need to calculate a date by subtracting the number of days from a given date. I know I could use an...
19
by: Ricardo Perez Lopez | last post by:
Hello everyone: I'm a PostgreSQL newbie, working now with dates, times, timestamps and intervals. I have three questions about the above: FIRST: --------
3
by: Mark | last post by:
I want to simply get the unix style epoch time (number of secs to now from Jan 01, 1970 UTC) for use as a timestamp to track the staleness of some objects. So I don't care about time zones or...
5
by: Grey Alien | last post by:
I need to convert timestamps that are given as the number of seconds that have elapsed since midnight UTC of January 1, 1970, (not counting leap seconds). It seems all of the std C functions...
11
by: usenet | last post by:
Is the epoch time the number of seconds elapsed since January 1st 1970 in my timezone or as per UTC? I mean, if A's program makes a call to time() in Melboune and B's program makes a call to...
5
by: Konstantinos Pachopoulos | last post by:
Hi, does any body now any such algorith? to find difference in days from YYYYMMDD to YYYYMMDD? Or just an algorithm, that converts YYYYMMDD to seconds since the epoch? Thanks
2
by: Richard Rossel | last post by:
Hi friends, I need a little help here, I 'm stuck with epoch calculation issue. I have this datetime: date_new = datetime(*time.strptime('20080101T000000','%Y%m%dT%H%M%S') ) This date_new is in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.