Date Conversion with Zero Padding

Post Reply
CiskoWalt
Posts: 46
Joined: Thu Oct 16, 2008 4:02 pm

Date Conversion with Zero Padding

Post 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
User avatar
mattgoff
MVP
Posts: 518
Joined: Fri May 16, 2008 1:37 pm
OLAP Product: TM1
Version: 10.2.2.6
Excel Version: O365
Location: Florida, USA

Re: Date Conversion with Zero Padding

Post by mattgoff »

Check out NUMBR.

Matt
Please read and follow the Request for Assistance Guidelines. It helps us answer your question and saves everyone a lot of time.
ajain86
Community Contributor
Posts: 132
Joined: Thu Oct 15, 2009 7:45 pm
OLAP Product: TM1
Version: 9.4.1 9.5 9.5.1
Excel Version: 2003 2007

Re: Date Conversion with Zero Padding

Post 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 );
Ankur Jain
CiskoWalt
Posts: 46
Joined: Thu Oct 16, 2008 4:02 pm

Re: Date Conversion with Zero Padding

Post 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);
Post Reply