Re: [Tutor] datetime a.m. not AM
Well, I have managed to get it working by using the locale setting. It would be nice to use the am/pm setting only and leave the rest unset. Will have to look into it further. Any tips? import locale #to set locale to use a.m. instead of AM locale.setlocale(locale.LC_ALL, '') bevan j wrote: > > Hello, > > I have an issue with data that I am trying to convert to datetime. It has > 'a.m.' rather than 'am' and the %p format doesn't seem to work. I am > pretty sure there should be an easy solution. That said I can not see it > at the moment. the following illustrates the issue. test1 and test2 work > BUT my data is in the format of 'data below: > > import StringIO > import datetime > > test1 = '1/09/1978 1:00:00 ' > test2 = '1/09/1978 1:00:00 am' > data = '1/09/1978 1:00:00 a.m.' > > print datetime.datetime.strptime(test1,('%d/%m/%Y %I:%M:%S ')) > print datetime.datetime.strptime(test2,('%d/%m/%Y %I:%M:%S %p')) > print datetime.datetime.strptime(data,('%d/%m/%Y %I:%M:%S %p')) > > Thank you for your time, > > bevan > > -- View this message in context: http://old.nabble.com/datetime-a.m.-not-AM-tp27506228p27506926.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime a.m. not AM
On ma, 2010-02-08 at 13:02 -0800, bevan j wrote: > data = '1/09/1978 1:00:00 a.m.' If you know this will always be in the form of 'a.m.' you can replace it with 'am' by data.replace('a.m.','am'). Greets Sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] datetime a.m. not AM
Hello, I have an issue with data that I am trying to convert to datetime. It has 'a.m.' rather than 'am' and the %p format doesn't seem to work. I am pretty sure there should be an easy solution. That said I can not see it at the moment. the following illustrates the issue. test1 and test2 work BUT my data is in the format of 'data below: import StringIO import datetime test1 = '1/09/1978 1:00:00 ' test2 = '1/09/1978 1:00:00 am' data = '1/09/1978 1:00:00 a.m.' print datetime.datetime.strptime(test1,('%d/%m/%Y %I:%M:%S ')) print datetime.datetime.strptime(test2,('%d/%m/%Y %I:%M:%S %p')) print datetime.datetime.strptime(data,('%d/%m/%Y %I:%M:%S %p')) Thank you for your time, bevan -- View this message in context: http://old.nabble.com/datetime-a.m.-not-AM-tp27506228p27506228.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor