[ncl-talk] unable to convert date and time

Geeta Geeta geetag54 at yahoo.com
Thu Mar 19 23:55:40 MDT 2020


 Thanks dennis and Rick. 
the code works. 

Geeta.

     On Thursday, 19 March, 2020, 11:28:33 pm IST, Dennis Shea <shea at ucar.edu> wrote:  
 
 No function .... just straight forward programming. You can create a function if you want.

 month = (/"jan","feb","mar","apr","may","jun" \
          ,"jul","aug","sep","oct","nov","dec"/)

 yyyymmdd = 20090402

 yyyy    = yyyymmdd/10000
 mmdd = yyyymmdd-(yyyy*10000)
 mm     = mmdd/100
 dd       = mmdd-(mm*100)
 print("yyyy="+yyyy+": mm="+mm+": dd="+dd)

 DATE = sprinti("%0.2i", mm) + month(mm-1) + yyyy
 print(DATE)
On Thu, Mar 19, 2020 at 8:31 AM Rick Brownrigg via ncl-talk <ncl-talk at ucar.edu> wrote:

I think you want cd_string, not cd_convert:
    http://ncl.ucar.edu/Document/Functions/User_contributed/cd_string.shtml
>From those docs, I'm not sure it will give days as "2nd", "3rd"..."31st", etc, but it will certain give 2, or 02, etc. 
It looks like cd_convert is used to convert various linear time units, ex, "days from..." to "months from...", etc.
Rick

On Thu, Mar 19, 2020 at 3:46 AM Geeta Geeta via ncl-talk <ncl-talk at ucar.edu> wrote:

Hi 
in my code, I have extracted the dats which looks like 20090402 (2nd April2009).I have to convert it to the format 02apr2009. 

I am using cd_convert to write the date and time in the required format. 

Following is the lines from the code.  I have added units  to this variable YYMMDD

YYMMDD           =   stringtointeger(Split_name(1))            ; string variable

                    print(YYMMDD)
   YYMMDD at units     = "days since 0000-01-01 00:00:0.0"
;                      printVarSummary(YYMMDD)

    stime            =  cd_convert(YYMMDD,"%c%y")
;                       print(stime)


I get error like this
CDMS error: Error on relative units conversion: invalid units = %c%y

kindly suggest


Geeta.
_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200320/7af05478/attachment.html>


More information about the ncl-talk mailing list