Dates conversions [message #92255] |
Thu, 05 November 2015 10:47  |
lucesmm
Messages: 26 Registered: October 2014
|
Junior Member |
|
|
Hello I have a problem and I am trying to see if IDL can solve this
I have an initial date
08/05/2012 05:14:39
and then my data is arrange in days and fractions of days
DAY
9.77013 -> meaning 9.77013 days after the initial date
9.77037
9.77060
9.77083
9.77106
9.77130
9.77153
9.77175
9.77199
9.77222
9.77245
is there a way that IDL can help me to convert each point to real date and time given the start date and time ?
Thanks
|
|
|
Re: Dates conversions [message #92256 is a reply to message #92255] |
Thu, 05 November 2015 15:02   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 11/05/2015 11:47 AM, lucesmm@gmail.com wrote:
> Hello I have a problem and I am trying to see if IDL can solve this
>
> I have an initial date
> 08/05/2012 05:14:39
>
> and then my data is arrange in days and fractions of days
> DAY
> 9.77013 -> meaning 9.77013 days after the initial date
> 9.77037
> 9.77060
> 9.77083
> 9.77106
> 9.77130
> 9.77153
> 9.77175
> 9.77199
> 9.77222
> 9.77245
>
> is there a way that IDL can help me to convert each point to real
> date
and time given the start date and time ?
>
>
> Thanks
>
Yes, convert to Julian days:
IDL> dates = [9.77013, 9.77037, 9.77060, 9.77083, 9.77106, 9.77130,
9.77153, 9.77175, 9.77199, 9.77222, 9.77245]
IDL> jd = julday(8, 5, 2012, 5, 14, 39)
% Compiled module: JULDAY.
IDL> jdates = jd + dates
IDL> caldat, jdates, months, days, years, hours, minutes, seconds
% Compiled module: CALDAT.
IDL> print, hours
23 23 23 23 23
23 23
23 23 23 23
IDL> print, minutes
43 43 44 44 44
45 45
45 46 46 46
IDL> print, seconds
38.245639 58.927402 18.867587 38.725375
58.583163
19.347323 39.205112 58.238925 18.920688
38.778476
58.718661
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
|
|
|
Re: Dates conversions [message #92257 is a reply to message #92255] |
Thu, 05 November 2015 15:08   |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
On Thursday, 5 November 2015 10:47:30 UTC-8, luc...@gmail.com wrote:
> Hello I have a problem and I am trying to see if IDL can solve this
>
> I have an initial date
> 08/05/2012 05:14:39
>
> and then my data is arrange in days and fractions of days
> DAY
> 9.77013 -> meaning 9.77013 days after the initial date
> 9.77037
> 9.77060
> 9.77083
> 9.77106
> 9.77130
> 9.77153
> 9.77175
> 9.77199
> 9.77222
> 9.77245
>
> is there a way that IDL can help me to convert each point to real date and time given the start date and time ?
>
>
> Thanks
This should do it.
d0Str = '08/05/2012 05:14:39'
;; Assuming mm/dd/yyyy: correct?
d0Jul = 0.0D ; Initialize to Double for millisecond accuracy
ReadS, d0Str, d0Jul, $
Format='(C(CMOI2,X,CDI2,X,CYI4,X,CHI2,X,CMI2,X,CSI2))'
dOffsets = [9.77013, 9.77037, 9.77060, 9.77083, 9.77106, 9.77130, 9.77153, $
9.77175, 9.77199, 9.77222, 9.77245]
dJuls = d0Jul + dOffsets
Print, [d0Jul, dJuls], $
Format='(C(CMOI2.2,"/",CDI2.2,"/",CYI4.4,X,CHI2.2,":",CMI2.2, ":",CSI2.2))'
For output, I get:
08/05/2012 05:14:39
08/14/2012 23:43:38
08/14/2012 23:43:58
08/14/2012 23:44:18
08/14/2012 23:44:38
08/14/2012 23:44:58
08/14/2012 23:45:19
08/14/2012 23:45:39
08/14/2012 23:45:58
08/14/2012 23:46:18
08/14/2012 23:46:38
08/14/2012 23:46:58
Those are truncated seconds, by the way. For more precision (which may be illusory):
Print, [d0Jul, dJuls], $
Format='(C(CMOI2.2,"/",CDI2.2,"/",CYI4.4,X,CHI2.2,":",CMI2.2, ":",CSF6.3))'
08/05/2012 05:14:39.000
08/14/2012 23:43:38.232
08/14/2012 23:43:58.968
08/14/2012 23:44:18.840
08/14/2012 23:44:38.712
08/14/2012 23:44:58.584
08/14/2012 23:45:19.320
08/14/2012 23:45:39.192
08/14/2012 23:45:58.200
08/14/2012 23:46:18.936
08/14/2012 23:46:38.808
08/14/2012 23:46:58.680
Dick Jackson Software Consulting Inc.
Victoria, BC, Canada --- http://www.d-jackson.com
|
|
|
Re: Dates conversions [message #92258 is a reply to message #92257] |
Thu, 05 November 2015 15:15   |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
On Thursday, 5 November 2015 15:08:18 UTC-8, Dick Jackson wrote:
>
> This should do it.
>
> d0Str = '08/05/2012 05:14:39'
>
> ;; Assuming mm/dd/yyyy: correct?
>
> d0Jul = 0.0D ; Initialize to Double for millisecond accuracy
> ReadS, d0Str, d0Jul, $
> Format='(C(CMOI2,X,CDI2,X,CYI4,X,CHI2,X,CMI2,X,CSI2))'
>
> dOffsets = [9.77013, 9.77037, 9.77060, 9.77083, 9.77106, 9.77130, 9.77153, $
> 9.77175, 9.77199, 9.77222, 9.77245]
>
> dJuls = d0Jul + dOffsets
>
> Print, [d0Jul, dJuls], $
> Format='(C(CMOI2.2,"/",CDI2.2,"/",CYI4.4,X,CHI2.2,":",CMI2.2, ":",CSI2.2))'
As you can see (Hi, Mike!), there's a couple of ways to go about it. I should have made it clear that the variables "d0Jul" and "dJuls" were referring to Julian Day numbers for your "day 0" and the set of date/times that you're computing from the offsets. For more, see:
http://exelisvis.com/docs/Date_Time_Data.html
http://exelisvis.com/docs/Format_Codes.html#files_2839720996 _2823814
Cheers,
-Dick
Dick Jackson Software Consulting Inc.
Victoria, BC, Canada --- http://www.d-jackson.com
|
|
|
Re: Dates conversions [message #92259 is a reply to message #92256] |
Thu, 05 November 2015 15:29  |
lucesmm
Messages: 26 Registered: October 2014
|
Junior Member |
|
|
On Thursday, November 5, 2015 at 3:02:49 PM UTC-8, Mike Galloy wrote:
>> Hello I have a problem and I am trying to see if IDL can solve this
>>
>> I have an initial date
>> 08/05/2012 05:14:39
>>
>> and then my data is arrange in days and fractions of days
>> DAY
>> 9.77013 -> meaning 9.77013 days after the initial date
>> 9.77037
>> 9.77060
>> 9.77083
>> 9.77106
>> 9.77130
>> 9.77153
>> 9.77175
>> 9.77199
>> 9.77222
>> 9.77245
>>
>> is there a way that IDL can help me to convert each point to real
>> date
> and time given the start date and time ?
>>
>>
>> Thanks
>>
>
> Yes, convert to Julian days:
>
> IDL> dates = [9.77013, 9.77037, 9.77060, 9.77083, 9.77106, 9.77130,
> 9.77153, 9.77175, 9.77199, 9.77222, 9.77245]
> IDL> jd = julday(8, 5, 2012, 5, 14, 39)
> % Compiled module: JULDAY.
> IDL> jdates = jd + dates
> IDL> caldat, jdates, months, days, years, hours, minutes, seconds
> % Compiled module: CALDAT.
> IDL> print, hours
> 23 23 23 23 23
> 23 23
> 23 23 23 23
> IDL> print, minutes
> 43 43 44 44 44
> 45 45
> 45 46 46 46
> IDL> print, seconds
> 38.245639 58.927402 18.867587 38.725375
> 58.583163
> 19.347323 39.205112 58.238925 18.920688
> 38.778476
> 58.718661
>
> Mike
> --
> Michael Galloy
> www.michaelgalloy.com
> Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Thank you Mike, I was half way there already with the JulDay ... but I didn't know I could just add them up after!
|
|
|