473,748 Members | 8,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3735
praba kar <pr*********@ya hoo.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.or g> 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*********@ya hoo.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
32426
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 query to format the date returned as a timestamp without having to do the conversion in php. Can someone tell me what to put in my db query?
13
9299
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 three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted to the MYSQL date field. The type of field is INT (11) so that I can instead of the standard...
6
39815
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 days or older than the current system date. Instead it is deleting all new rows. LOG_TS is a timestamp but that should not matter since DATE returns just the date portion of a date or timestamp...right? I'm not a SQL guru but I can't see...
2
2167
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. ============================================================= while (($data = fgetcsv($handle,5000, ",")) !== FALSE) { $mydate = $data; // here is the array value that holds the date }
11
10573
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)) || '-' || RTRIM(CHAR(YEAR(COVG_TYP_STRT_DT))) FROM twd_coverage_type 1 ---------------------------------------------------------------------------------------------------------------------------- 6-May-2006 1 record(s) selected.
2
11514
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: CAST(O.MYDATE AS CHAR(30)) When directly updating date fields in the main table, the logged value gets saved in the format YYYY-MM-DD as expected.
10
39106
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 records. Can any of you experts out there help me with a sample SQL.
5
8096
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 I can say that my data is going to come in this format or do I need to convert it outside the database? -- Ewa
10
4023
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 problem. This function does not recognize time zones. How to adjust date to user's time zone? Is converting to timestamp() and then to format readable to visitors the one and only solution (e.g. strtotime() + date() OR DateTime object)? Perhaps,...
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.