Re: convert yyyymmdd to time values

From: Will Hobbs <Will.Hobbs_at_nyahnyahspammersnyahnyah>
Date: Sat Feb 01 2014 - 20:01:12 MST

Xi

You can use the fact that integers do not have decimal points to split the yyyymmdd dates into years, months,days, then use the cd_inv_calendar() function (http://www.ncl.ucar.edu/Document/Functions/Built-in/cd_inv_calendar.shtml)

e.g.

>time = 20011201 ; yyyymmdd time (1st December 2001)

>year = time/10000 ; year is an integer, 2001
> month = time%10000 ; this uses the modulus operator, month is now 1201 (http://www.ncl.ucar.edu/Document/Functions/Contributed/mod.shtml)
>day = month%100 ;day is an integer, 01
>month = month/100 ;month just has the month now i.e. 12

You can now plug these values into cd_inv_calendar to get whatever time array you need.

>Newtime = cd_inv_calender(year,month,day,0,0,0,time@units, 0)

I've used values of 0 for the hour,minute and seconds here (i.e. midnight), but you can use whatever valid time is appropriate for your data.

Will

From: Xi Chang <xi.chang01@gmail.com<mailto:xi.chang01@gmail.com>>
Date: Sunday, 2 February 2014 8:25 AM
To: "ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>" <ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>>
Subject: convert yyyymmdd to time values

Dear NCL members,

What should I do if I want to convert my yyyymmdd date format from a *txt output to time values? for instance,

time = (/20010101, 20010105, 20060302, 20080101, 20090621/)
time@units = "days since 1800-01-01 00:00:00"

So that I will have:

time = (/17522904, 17522928, 17522952, 17522976, 17523000/)
time@units = "days since 1800-01-01 00:00:00"

the reason is because I need to use the cd_calendar function for my purpose.

thank you

Chang

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Feb 1 20:01:28 2014

This archive was generated by hypermail 2.1.8 : Fri Feb 07 2014 - 16:39:11 MST