Re: Parsing dates (ARGH!) [message #39455] |
Mon, 17 May 2004 10:49 |
Chris[1]
Messages: 23 Registered: January 2003
|
Junior Member |
|
|
The format you have supplied (the "C()" format) returns a Julian date as a
floating point number (use double precision). Then use the caldat procedure
to transfer this to numeric values for year, month,day, etc. i.e
IDL> x = 0d0
IDL>reads, a, x, format=sql_fmt
IDL>caldat,x,month,day,year,hour,minute,second
Chris
"Jamie Smyth" <jamiesmyth_uni@yahoo.ca> wrote in message
news:120533fa.0405170849.31c48ec6@posting.google.com...
> Can someone please explain how I can parse the year, month, day, hour,
> minute, and seconds from a timestamp such as '2004-01-01
> 01:22:15.1234'
>
> IDL> print, a
> 2004-01-01 00:10:22
> IDL> print, size(a, /tname)
> STRING
> IDL> sql_fmt = "(C(CYI4, X, CMoI2.2, X, CDI2.2, X, CHI2.2, X," + $
> IDL> " CMI2.2, X, CSF7.4))"
> IDL> reads, a, year, format=sql_fmt
> IDL> help, year
> YEAR INT = 28173
> IDL> reads, a, year, month, date, hour, minute, seconds,
> format=sql_fmt
> % READS: End of input data encountered: A
> % Execution halted at: $MAIN$
>
> Thanks, I've blown most of the morning on this...
|
|
|
Re: Parsing dates (ARGH!) [message #39456 is a reply to message #39455] |
Mon, 17 May 2004 10:41  |
Rick Towler
Messages: 821 Registered: August 1998
|
Senior Member |
|
|
"Jamie Smyth" wrote...
> Can someone please explain how I can parse the year, month, day, hour,
> minute, and seconds from a timestamp such as '2004-01-01
> 01:22:15.1234'
Probably not the fastest or most elegant but:
IDL> a='2004-01-01 00:10:22'
IDL> ddtt=STRSPLIT(a,' ', /EXTRACT)
IDL> date=STRSPLIT(ddtt[0],'-',/EXTRACT)
IDL> time=STRSPLIT(ddtt[1],':',/EXTRACT)
IDL> print, date
2004 01 01
IDL> print, time
00 10 22
date and time will be 3 element vectors where date[0] is year, time[0] is
hour, date[1] is month, time[1] is minute, etc...
-Rick
|
|
|
Re: Parsing dates (ARGH!) [message #39458 is a reply to message #39456] |
Mon, 17 May 2004 10:27  |
btt
Messages: 345 Registered: December 2000
|
Senior Member |
|
|
Jamie Smyth wrote:
> Can someone please explain how I can parse the year, month, day, hour,
> minute, and seconds from a timestamp such as '2004-01-01
> 01:22:15.1234'
>
> IDL> print, a
> 2004-01-01 00:10:22
> IDL> print, size(a, /tname)
> STRING
> IDL> sql_fmt = "(C(CYI4, X, CMoI2.2, X, CDI2.2, X, CHI2.2, X," + $
> IDL> " CMI2.2, X, CSF7.4))"
> IDL> reads, a, year, format=sql_fmt
> IDL> help, year
> YEAR INT = 28173
> IDL> reads, a, year, month, date, hour, minute, seconds,
> format=sql_fmt
> % READS: End of input data encountered: A
> % Execution halted at: $MAIN$
>
> Thanks, I've blown most of the morning on this...
Hello,
You could try ....
IDL> b = strsplit(a, '[- :]', /extract)
IDL> for i = 0, n_elements(b)-1 do print, i,' = ', b[i]
0 = 2004
1 = 01
2 = 01
3 = 00
4 = 10
5 = 22
Ben
|
|
|