Date formats

Duncan Booth duncan at NOSPAMrcp.co.uk
Fri Jun 14 04:24:04 EDT 2002


Max M <maxm at mxm.dk> wrote in news:3D09A1B1.6040705 at mxm.dk:

> 
>      gDateFormat = '%d-%m-%Y'
> 
> This give dates of the type:
> 
>      01-01-2002
> 
> For some reason my customer wants dates of the type:
> 
>      1-1-2002
> 
> Without the leading zero in single digit dates. But when I look in the 
> docs for date time formats there is no way to specify days and months in 
> that format.

The documentation says that on some platforms an optional field width and 
precision specification can follow the initial '%'. This is obviously 
highly non-portable, but might provide a suitable solution if you are not 
desperate for portability. For example, if you are running under Windows 
using "%#d-%#M-%Y" as the format string gives the format you require.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list