[Tutor] help regarding string

Kent Johnson kent37 at tds.net
Sun Jul 2 12:20:58 CEST 2006


anil maran wrote:
> please help me format this string from 
> input : 2006-06-16 16:23:27.703000 to
> output: 2006-06-16 16:23:27
> 
> or 2006-06-16 4:23:27 PM

str.split() can extract everything up to the first period:
In [4]: '2006-06-16 16:23:27.703000'.split('.')[0]
Out[4]: '2006-06-16 16:23:27'

Kent



More information about the Tutor mailing list