473,473 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

strtotime?

PHP has a very nice strtotime function (http://php.net/strtotime) which
converts a date/time in virtually any format into a timestamp. Does
Python have a similar function?

Jul 18 '05 #1
5 4805
Leif K-Brooks wrote:
PHP has a very nice strtotime function (http://php.net/strtotime) which
converts a date/time in virtually any format into a timestamp. Does
Python have a similar function?


I guess you're looking for: time.strptime

--Irmen
Jul 18 '05 #2
Irmen de Jong wrote:
PHP has a very nice strtotime function (http://php.net/strtotime)
which converts a date/time in virtually any format into a timestamp.
Does Python have a similar function?


I guess you're looking for: time.strptime


Thanks, but no. PHP's strtotime() function magically guesses the format
on its own, time.strptime() just uses a fixed format.

Jul 18 '05 #3
Leif K-Brooks wrote:

Irmen de Jong wrote:
PHP has a very nice strtotime function (http://php.net/strtotime)
which converts a date/time in virtually any format into a timestamp.
Does Python have a similar function?


I guess you're looking for: time.strptime


Thanks, but no. PHP's strtotime() function magically guesses the format
on its own, time.strptime() just uses a fixed format.


Perhaps the mx.DateTime package would help:

From http://www.lemburg.com/files/python/mxDateTime.html:
------------------------------
DateTimeFrom(*args,**kws)

Constructs a DateTime instance from the arguments.

This constructor can parse strings, handle numeric arguments and knows about
the keywords year,month,day,hour,minute,second.

It uses type inference to find out how to interpret the arguments and makes
use of the Parser module.
------------------------------

-Peter
Jul 18 '05 #4
Peter Hansen wrote:
Leif K-Brooks wrote:
Irmen de Jong wrote:
> PHP has a very nice strtotime function (http://php.net/strtotime)
> which converts a date/time in virtually any format into a timestamp.
> Does Python have a similar function?

I guess you're looking for: time.strptime


Thanks, but no. PHP's strtotime() function magically guesses the format
on its own, time.strptime() just uses a fixed format.


Perhaps the mx.DateTime package would help:


Or DateUtil:

https://moin.conectiva.com.br/DateUtil
parse("3rd of May 2001")

datetime.datetime(2001, 5, 3, 0, 0)

yours,
Gerrit.

--
6. If any one steal the property of a temple or of the court, he shall
be put to death, and also the one who receives the stolen thing from him
shall be put to death.
-- 1780 BC, Hammurabi, Code of Law
--
PrePEP: Builtin path type
http://people.nl.linux.org/~gerrit/c.../pep-xxxx.html
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

Jul 18 '05 #5
have a look at the parsedate() method in the RFC822 package.
It may help you if your date is in "Internet format"

"parsedate(StringDate)
Attempts to parse a date according to the rules in RFC 2822. however,
some mailers don't follow that format as specified, so parsedate() tries
to guess correctly in such cases. date is a string containing an RFC
2822 date, such as 'Mon, 20 Nov 1995 19:12:08 -0500'. If it succeeds in
parsing the date, parsedate() returns a 9-tuple that can be passed
directly to time.mktime(); otherwise None will be returned. Note that
fields 6, 7, and 8 of the result tuple are not usable."
Leif K-Brooks wrote:
PHP has a very nice strtotime function (http://php.net/strtotime) which
converts a date/time in virtually any format into a timestamp. Does
Python have a similar function?

Jul 18 '05 #6

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

Similar topics

3
by: Pjotr Wedersteers | last post by:
I'm using strtotime to get the timestamp for midnight. I have a statistics script for my pagecounter that displays hits since midnight. I also display the number of hours and minutes passed since...
1
by: peabody | last post by:
I'm trying to use the strtotime() function to manage sessions. But I get the following <?php print(time() . " - " . strtotime("+1 hour")); ?> outputs: 1097380666 - 1097308800
7
by: Rithish | last post by:
Hello. I noticed a strange thing while using strtotime() and date() functions in combination to generate from MySQL into a readable format. By default, the MySQL date field will be 0000-00-00...
18
by: windandwaves | last post by:
Hi Folk I love the strtotime function, because I can make a date field in a form and just tell my users to enter whatever they want and as long as it is a date, it will work. HOWEVER, this...
6
by: Brian Kendig | last post by:
I'm working with dates in several formats including 'yyyy MMM dd', but strtotime doesn't recognize this format and returns FALSE. Is there a direct way to convert times from this format into...
5
by: cla | last post by:
I'm using this code on an application to track football schedules: ---- $season = '2005'; $basedate = strtotime('this friday', strtotime('31 August '.$season)); for($d=0;$d<=31;$d++) {...
5
by: Chris | last post by:
I am trying to output Monday of the current week i.e. if Monday is the 8th I want to display 'Monday 8th' for any date between Monday 8-14th. I would appreciate any help, the code below is...
3
by: Anthony Smith | last post by:
So, after doing some research I finally figured that php chokes on dates past year 2525. In this web service that I use they often use 2525-05-31 as the expiration date. I want to determine how I...
9
by: Erwin Moller | last post by:
Hi group, I have been using strtotime a lot in my code. I wonder if I made a mistake in my thinking. :-/ Here follows a stripped down example. consider some dates: $date1 = "2008-02-23";...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.