Page 1 of 1

NewDateFormatter Use

Posted: Thu Jul 30, 2020 10:31 am
by MarenC
Hi,

I want to get the serial date of the following date:

31/07/2020.

Normally I would subst this and use DayNo.

But I thought I would try the following:

Code: Select all

cDate = '31/07/2020';

vDateFormater = NewDateFormatter('');
vDateCompareSerial = ParseDate(vDate, 'dd/mm/yyyy');
vDateCompare = FormatDate( vDateCompareSerial, 'yyyy-mm-dd' );
I get the following results when I output to excel:

vDateCompareSerial = 21945.004861111
vDateCompare = 31/07/2020

But vDateCompareSerial equates to 31/01/2020 and not 31/07/2020.

What is going on?

Maren

Re: NewDateFormatter Use

Posted: Thu Jul 30, 2020 11:43 am
by Wim Gielis
Did you check the documentation on the date patterns ?
http://userguide.icu-project.org/formatparse/datetime

I would use 'dd/LL/y' and 'dd LL y' for your patterns.

Re: NewDateFormatter Use

Posted: Thu Jul 30, 2020 12:18 pm
by MarenC
Hi Wim,

I didn't know I did need to check those patterns so thanks for that.

I see the issue now, the small m was presuming minute.

If I change it as follows it appears to work:

Code: Select all

cDate = '31/07/2020';

vDateFormater = NewDateFormatter('');
vDateCompareSerial = ParseDate(vDate, 'dd/MM/yyyy');
vDateCompare = FormatDate( vDateCompareSerial, 'dd/MM/yyyy' );
Your patterns work too but I wanted the patterns to resemble the vDate and M is more familiar than L for months

thanks for your assistance

Maren

Re: NewDateFormatter Use

Posted: Thu Jul 30, 2020 12:35 pm
by Wim Gielis
MarenC wrote: Thu Jul 30, 2020 12:18 pm Hi Wim,

I didn't know I did need to check those patterns so thanks for that.

I see the issue now, the small m was presuming minute.

If I change it as follows it appears to work:

Code: Select all

cDate = '31/07/2020';

vDateFormater = NewDateFormatter('');
vDateCompareSerial = ParseDate(vDate, 'dd/MM/yyyy');
vDateCompare = FormatDate( vDateCompareSerial, 'dd/MM/yyyy' );
Your patterns work too but I wanted the patterns to resemble the vDate and M is more familiar than L for months

thanks for your assistance

Maren
Hi,

indeed MM is an option too.