Date Control value is previous day

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
paularstall
Posts: 11
Joined: Tue Oct 09, 2018 2:09 am

Date Control value is previous day

Post by paularstall » Thu Jun 11, 2020 10:24 pm

Hi.

I'm having a strange problem trying to get the date value returned from the PRIM_MD.DateTime control.

When the users selects a date from the calendar it correctly displays on the screen, however when I try and assign the value to another field it always displays the previous days date.
I'm in the UK could this be a timezone issue?

User selects 8th June 2020
DateSelect.PNG
DateSelect.PNG (7.36 KiB) Viewed 1328 times
After Clicking save I can see the value of the control using a console log
ConsoleLog.PNG
ConsoleLog.PNG (5.08 KiB) Viewed 1328 times
The value is showing as 7th June 2020

Here's the relevant code

Code: Select all

Define_Com Class(#PRIM_MD.DateTime) Name(#ResponseDate) Caption('Date') Displayposition(2) Icon('date_range') Iconopacity(50) Left(253) Parent(#AnswerPanel) Tabposition(3) Width(300) Themedrawstyle('LightTitle') Top(46) Dateformat(Custom) Customdateformat('DDDD, D MMM YYYY')


Evtroutine Handling(#SaveResponse.Click)
#ApptDateFormat := #ResponseDate.value.AsDisplayString( CCYYMMDDHHMMSS )
#ApptDatex := #ResponseDate.Value
#SYS_WEB.console.log Text('Save Clicked Date - ' + #ApptDatex.AsString + ' - ' + #ApptSlot)
#SYS_WEB.console.log Text('Date Format - ' + #ApptDateFormat)
Endroutine
Any ideas what's going on here, and what I can do to fix it?
I'm at the point of forgetting the control altogether and just having the user type the date.

Cheers
Paul.

jyoung
Posts: 690
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Date Control value is previous day

Post by jyoung » Thu Jun 11, 2020 11:39 pm

I had the same issue some time ago and I raised an issue with support, this was before the Idera acquisition and the move to the new support system, however I think the solution was to use the STD_DATEX field instead of the PRIM_MD.DateTime.

I forget the exact details as to why, but it was something with how they were treating ISO dates (i think :S)

Might give STD_DATEX a try and see if you get the correct results.

Hope this helps,
Joe

paularstall
Posts: 11
Joined: Tue Oct 09, 2018 2:09 am

Re: Date Control value is previous day

Post by paularstall » Fri Jun 12, 2020 12:28 am

Thanks Joe
I'll give that a try :)

paularstall
Posts: 11
Joined: Tue Oct 09, 2018 2:09 am

Re: Date Control value is previous day

Post by paularstall » Fri Jun 12, 2020 12:40 am

Hi Joe.

Many thanks for that. It now works perfectly :!:

Thanks
Paul.

andrewhiom
Posts: 12
Joined: Wed May 11, 2016 10:52 am

Re: Date Control value is previous day

Post by andrewhiom » Tue Sep 15, 2020 1:06 pm

i'm in australia and have the same issue. this is what i'm doing to wedge the 'correct' date into a signed(8,0) field:

#ecdatprc := #dateProcessed.value.asLocalizedDateTime.date.asNumber( ccyymmdd )

a bit contorted, but it works.

BrendanB
Posts: 45
Joined: Tue Nov 24, 2015 10:29 am

Re: Date Control value is previous day

Post by BrendanB » Wed Sep 16, 2020 9:20 am

Andy,

the important part is
#dateProcessed.value.asLocalizedDateTime

the value returned from the datepicker is a UTC datetime... so when you get the 'date' if you dont specify to LocalizeDateTime, then you will get the UTC date (without the UTC adjustment).

so for example, sydney is +10 hours, so if you select a date (and dont select a time -- the time remains at midnight by default), then when you get the date you get 'the day before the one you picked'.

asLocalizedDateTime will adjust it by the UTC offset to get to the correctly selected date.

Brendan.

Post Reply