[Thread Prev][Thread Next][Index]

Re: [ferret_users] constructing output file names with zero-filled current date string



Hi,

there's also a way to do this kind of thing with Ferret string functions:

yes? let dates_in = {" 2-apr-18", "12-apr-18"}

yes? let dates = if substring(dates_in, 1, 1) EQ " " then  strcat ("0", substring(dates_in, 2, strlen(dates_in)) ) else dates_in

yes? list dates
             VARIABLE : IF SUBSTRING(DATES_IN, 1, 1) EQ " " THEN  STRCAT ("0", SUBSTRING(DATES_IN, 2, STRLEN(DATES_IN)) ) ELSE DATES_IN
             SUBSET   : 2 points (X)
 1   / 1:"02-apr-18"
 2   / 2:"12-apr-18"

On 4/3/2018 6:14 AM, Ge Peng - NOAA Affiliate wrote:
Hi Ryo,

 It is the exact what I was looking for:

   let cDate = spawn("date --date='($current_date)' +'%d–%b–%y'")

   define sym cdate `cDate`

    !-> define sym cdate 03–Apr–18
    

Thanks a lot for the solution!

--- Peng


On Mon, Apr 2, 2018 at 10:48 PM, Ryo Furue <furue@xxxxxxxxxx> wrote:
Hi Peng,

I need to extract the current date and use it in my output file name. How do I convert:

 

    current_date =” 2-Apr-18”

 

to a fix length, zero-filled date string: cDate=“02-Apr-18”?  


let a = SPAWN("gdate --date='2-Apr-18' +'%d-%b-%y'")
define symbol cDate `a`

The SPAWN() function runs the shell command and gets its output.  I use the command "gdate" above for the GNU version of the "date" command.  On Linux, use "date".  To check if it's the right date command, look at "date --version".

Ryo



--

Ge Peng, PhD
Research Scholar
Cooperative Institute for Climate and Satellites - NC (CICS-NC)/NCSU at

NOAA’s National Centers for Environmental Information (NCEI)

Center for Weather and Climate (CWC)

151 Patton Ave, Asheville, NC 28801
+1 828 257 3009; ge.peng@xxxxxxxx

ORCID: http://orcid.org/0000-0002-1986-9115

Following CICS-NC on Facebook





[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement