Skip to main content
Known Participant
Mar 30, 2022 12:48 AM UTC
Question

issue with converting date to string

Hi there,

I need to use the date string in format "YMMd", for example, "20220329" for today.

I am using the datetext function: datetext(today(), "YMMd"),  if today() function return "03/29/2022", then the datetext(today(), "YMMd") will return "20200328". what's the issue there? why I cant get "20220329"? what's the good way to archive it?

Thanks!

Lin 

12 replies

linp0001Author
Known Participant
Mar 30, 2022 12:50 AM UTC

sorry the datetext(today(), "YMMd") return "20220328", not "20200328" 

mathieud0001
Genius
Mar 30, 2022 2:24 AM UTC

Date format should be "yyyyMMdd"

Also be aware of this: community.appian.com/.../kb-1344-datetext-returns-one-day-before-expected-date

arockiaprincyv0003
Participating Frequently
Mar 30, 2022 3:30 AM UTC

today() function returns the current day in Greenwich Mean Time (GMT) so the result may differ from the current day in your local timezone.

gopalk2865
Participating Frequently
Mar 30, 2022 3:55 AM UTC

Hi, I am using the same code which you are using and i am getting expected result, please see below. I would suggest you check your environment time zone.

linp0001Author
Known Participant
Mar 30, 2022 2:12 PM UTC

if you run just today(), you got the same date?

gopalk2865
Participating Frequently
Mar 30, 2022 2:23 PM UTC

yes, i am getting the same result .

mikes0011
Brainy
Mar 30, 2022 2:01 PM UTC

FWIW I always seem to have better results using "text()" for these, rather than "datetext()".  Also as Princy noted above already, you need to account for GMT conversion - I would suggest trying the same code but with "today()" wrapped in "local()".

The Expression Guru
linp0001Author
Known Participant
Mar 30, 2022 2:11 PM UTC

Thanks Mike, it's working.

sairohitd054766
Inspiring
Apr 6, 2022 8:27 AM UTC

text(today(),"yyyyMMdd") 
This returns the expected one.

linp0001Author
Known Participant
Apr 7, 2022 4:36 PM UTC

thank you.