473,385 Members | 1,379 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,385 software developers and data experts.

Reg Date string conversion into timestamp function


Dear All,

I have doubt regarding date string to time
conversion function. In Python I cannot find flexible
date string conversion function like php strtotime. I
try to use following type
function
1) parsedate function failed if a date string
like below format "16-MAY-2005 01:26"
2)parsedate_tz function also failed if a date string
is different format

if any one find some other date string conversion
function kindly let me know
__________________________________________________ ______________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
Jul 19 '05 #1
3 3709
praba kar <pr*********@yahoo.co.in> writes:
Dear All,

I have doubt regarding date string to time
conversion function. In Python I cannot find flexible
date string conversion function like php strtotime. I
try to use following type
function
1) parsedate function failed if a date string
like below format "16-MAY-2005 01:26"
parsedate is documented as trying to parse RFC 2822 dates. Your
example isn't one.
2)parsedate_tz function also failed if a date string
is different format
See the above comments for why.
if any one find some other date string conversion
function kindly let me know


In my experience, it's not very common to have to deal with arbitrary
time/date strings formats. Typically, a source will only provide date
strings in one format, so you only have to be able to deal with that
format in your application. For instance, all dates in email headers
should follow RFC2822, which means the parsedate you found is adequate
for any application dealing with email headers.

Given the wide variety of date strings possible in the wild, a routine
that swallows a such a string and produces a date is going to have to
guess what format is being used - and there are formats that can't be
told apart for some dates. As such, such a routine isn't very
pythonic.

With all that said, you can use strptime to buid a date/time
parser. If you really need to deal with multiple formats from one
source, maybe if you describe your application some help could be
provided.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #2
praba kar wrote:
I have doubt regarding date string to time
conversion function. In Python I cannot find flexible
date string conversion function like php strtotime. I
try to use following type
function
1) parsedate function failed if a date string
like below format "16-MAY-2005 01:26"
2)parsedate_tz function also failed if a date string
is different format


Since that's not an RFC2822 date, it shouldn't really be surprising that
a function that is designed to parse RFC2822 dates would fail to parse
it properly...

Have you looked at the mxDateTime package's Parser submodule yet?
http://www.egenix.com/files/python/m...me.html#Parser

-Peter
Jul 19 '05 #3
"praba kar" <pr*********@yahoo.co.in> wrote:

Dear All,

I have doubt regarding date string to time
conversion function. In Python I cannot find flexible
date string conversion function like php strtotime. I
try to use following type
function
1) parsedate function failed if a date string
like below format "16-MAY-2005 01:26"
2)parsedate_tz function also failed if a date string
is different format

if any one find some other date string conversion
function kindly let me know


Check the other thread posted today with almost the same topic
(http://tinyurl.com/bpcg8).

George

Jul 19 '05 #4

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

Similar topics

2
by: Ben | last post by:
I would like to use php to query a database and retrieve a unix timestamp. The problem is that mysql is storing the data in the date format and not a timestamp. I am sure that I can amend my...
13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
6
by: bryan.seaton | last post by:
I have a delete statement that is not doing what I want it to do: Delete from LOG_TABLE where (DATE(LOG_TS)) < (DATE(CURRENT_DATE)- 21 DAYS); It is supposed to delete all records that are 21...
2
by: johndcal | last post by:
Hello All, I have a date value that I pull from a .csv file. After reading the file and storing the values in an array the value of the date could be found in $array, for example....
11
by: shsandeep | last post by:
I used the following query to retrieve the date in dd-mon-yyyy format. db2 => SELECT RTRIM(CHAR(DAY(COVG_TYP_STRT_DT))) || '-' || RTRIM(MONTHNAME(COVG_TYP_STRT_DT)) || '-' ||...
2
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: ...
10
by: satishrajana | last post by:
Hi, My SQL returns a NULL in a datefield if there is no date in that field. If there is a NULL in this column, I want to replace it with spaces in my SELECT statement when I am selecting these...
5
by: E.Bartosiewicz | last post by:
I have several files with data I would like to import into DB2, but I have timestamps set in a format, which DB2 can't catch - DD-MM-YYYY HH:MM:SS DB2 wants to get the year first. Is there a way...
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.