Page 1 of 1

Date Conversion with Zero Padding

Posted: Thu Dec 30, 2010 7:10 pm
by CiskoWalt
How can I convert the dates in the formats below to" YYYY-MM-DD?

thanks,

Walt

# The date value on the file to be imported is in the following formats:
# m/d/yyyy
# mm/d/yyyy
# mm/dd/yyyy
# SUBST(string, beginning, length)

sMonth = SUBST(v_order_day,0,(SCAN( '/', v_order_day)-1));
sDayMonth = SUBST(v_order_day,(SCAN( '/', v_order_day)+1), Long(v_order_day));
sYear = SUBST(sDayMonth,(SCAN( '/', sDayMonth)+1), Long(sDayMonth));
sDay = SUBST(sDayMonth,0,(SCAN( '/', sDayMonth)-1));

# DATES(1998, 2, 10) returns '1998-02-10' # convert date to number.
sOrderDateString = DATES(sYear, sMonth, sDay); ----this does not work function expects numbers
l_OrderDateSerial = DayNo( sOrderDateString );


Thanks,

Walt

Re: Date Conversion with Zero Padding

Posted: Mon Jan 03, 2011 5:55 pm
by mattgoff
Check out NUMBR.

Matt

Re: Date Conversion with Zero Padding

Posted: Mon Jan 03, 2011 7:06 pm
by ajain86
sMonth = SUBST(v_order_day,0,(SCAN( '/', v_order_day)-1));
sDayMonth = SUBST(v_order_day,(SCAN( '/', v_order_day)+1), Long(v_order_day));
sYear = SUBST(sDayMonth,(SCAN( '/', sDayMonth)+1), Long(sDayMonth));
sDay = SUBST(sDayMonth,0,(SCAN( '/', sDayMonth)-1));

# convert to numeric values
nMonth = NUMBR( sMonth );
nDay = NUMBR( sDay );
nYear = NUMBR( sYear );

# DATES(1998, 2, 10) returns '1998-02-10' # convert date to number.
sOrderDateString = DATES(nYear, nMonth, nDay); ----this does not work function expects numbers
l_OrderDateSerial = DayNo( sOrderDateString );

Re: Date Conversion with Zero Padding

Posted: Mon Jan 03, 2011 8:53 pm
by CiskoWalt
Thank You. NUMBER works!

# The date value on the file to be imported is in the following formats:
# m/d/yyyy
# mm/d/yyyy
# mm/dd/yyyy

# Example: SUBST(string, beginning, length)

sDayYear = SUBST(v_order_day,(SCAN( '/', v_order_day)+1), Long(v_order_day));
nMonth = NUMBR(TRIM(SUBST(v_order_day,1,(SCAN( '/', v_order_day)-1))));
nYear = NUMBR(TRIM(SUBST(sDayYear,(SCAN( '/', sDayYear)+1), Long(sDayYear))));
nDay = NUMBR(TRIM(SUBST(sDayYear,1,(SCAN( '/', sDayYear)-1))));

# ASCIIOutput('c:\helpme.txt', sDayYear, nMonth , nYear, nDay );


# Example: DATES(1998, 2, 10) returns '1998-02-10'
sOrderDateString = DATES(nYear, nMonth, nDay);

# Convert Date to Serial number.
l_OrderDateSerial = DayNo(sOrderDateString);