Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62661 > unrolled thread

Re: How to check the date validity?

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2013-12-24 00:42 +0000
Last post2013-12-24 00:42 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to check the date validity? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-24 00:42 +0000

#62661 — Re: How to check the date validity?

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-12-24 00:42 +0000
SubjectRe: How to check the date validity?
Message-ID<mailman.4581.1387845790.18130.python-list@python.org>
On 24/12/2013 00:30, Igor Korot wrote:
> Hi, ALL,
> I'm working on the python script which reads the data from the csv file.
> In this file I have 3 different kind of fields: one consist of the
> sole date, one - sole time and one - datetime. The time includes
> milliseconds, i.e. "12:55:55.705"
> All fields of the file including those 3 I am reading as the string.
> All those strings after validating will go into mySQL table.
>
> Now, it looks that the python way of validating the date/time of the
> string is to call strptime(). However looking at the docs and trying
> to use the function I didn't find a way to check for the milliseconds.
> Now the dates can be formatted differently I think according to the
> locale under which the csv is generated.
>
> So, my question is: since there is a simple way of inserting
> preformatted string into the datetime field of mySQL, how do I
> validate the date string?
> I don't want to convert that string to datetime object, just want to
> check if all those types of dates are good dates and does not contain
> garbage.
>
> I tried to do an RE, but its static validation and so will not work in
> all cases.
>
> Thank you for any hints.
>

You actually need the %f format code for milliseconds, not microseconds. 
  Note 5 from 
http://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior 
"When used with the strptime() method, the %f directive accepts from one 
to six digits and zero pads on the right. %f is an extension to the set 
of format characters in the C standard (but implemented separately in 
datetime objects, and therefore always available)"

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web