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 »

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 47084 times
After Clicking save I can see the value of the control using a console log
ConsoleLog.PNG
ConsoleLog.PNG (5.08 KiB) Viewed 47084 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: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Date Control value is previous day

Post by jyoung »

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 »

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 »

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 »

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: 134
Joined: Tue Nov 24, 2015 10:29 am

Re: Date Control value is previous day

Post by BrendanB »

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.
adale
Posts: 210
Joined: Wed Apr 08, 2020 9:18 pm
Location: Poplarville, MS

Re: Date Control value is previous day

Post by adale »

andrewhiom wrote: 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.
Thank you for this bit. It solved the exact issue I was currently working on.
Arlyn Dale
Servias LLC
adale
Posts: 210
Joined: Wed Apr 08, 2020 9:18 pm
Location: Poplarville, MS

Re: Date Control value is previous day

Post by adale »

I initially thought I had this issue solved, but I must still have something off with the weblet as it does not display the correct (or expected) input date.
Maybe someone here can point out what I have out of sorts.

Using the #PRIM_MD.DateTime weblet(#inputDate) to present a date input calendar, where the use can select a date in the past. I am wanting to initially default the calendar to yesterday (today - 1).

The values would appear to calculate correctly for the inputDate to be yesterday's date, but the weblet continues to show up with the date prior to the input date?

What am I missing?

Code where I am trying to load yesterday's date:

Code: Select all

EVTROUTINE Handling(#COM_OWNER.Prepare)
DEFINE Field(#DTTEST) Type(*Dec) Length(8) Decimals(0)

* Set weblet to yesterday's date
#STD_DATEX := #DATETIMEX.AsLocalizedDateTime.date.Adjust( -1 )

* Console - debug
#sys_web.Console.Log( ('STD_DATEX: ' + ' - ' + #STD_DATEX.AsDisplayString) )

* load input date to weblet
#inputDate := #STD_DATEX

* get input value as number
#DTTEST := #inputDate.Value.Date.AsNumber( CCYYMMDD )

* Console - debug
#sys_web.Console.Log( ('INPUTDATE: ' + ' - ' + #DTTEST.AsDisplayString) )

* load DTTEST as string for display in view
#txYesterdayDate.Caption := 'Date should be today -1 (' + #DTTEST.AsString + ' )'

* load STD_DATES as string for display in view
#txInputDateValue.Caption := 'InputDate value: ' + #STD_DATEX.AsString

ENDROUTINE

Images from my VL view.
Date_Weblet_view.png
Date_Weblet_view.png (75.46 KiB) Viewed 39564 times
Date_Weblet_expanded.png
Date_Weblet_expanded.png (44.43 KiB) Viewed 39564 times
Arlyn Dale
Servias LLC
adale
Posts: 210
Joined: Wed Apr 08, 2020 9:18 pm
Location: Poplarville, MS

Re: Date Control value is previous day

Post by adale »

My case is for VL Web use where I have data from legacy files.
From what I gather, the #PRIM_MD.DateTime control is specifically or intrinsically looking for the an incoming parm value to have both the date and the time values populated. If only providing a date, and no time, then the control assumes the time value to be midnight.

The #PRIM_MD.DateTime control is expecting the date and time to use as DisplayasUTC (or at lease I can't find an option to make this accept AsLocalizedDateTime.

We have legacy date fields that are 8.0 decimal value fields (CCYYMMDD), so no time value is included.
And since the incoming date parm is a decimal value field, I am unable to utilize the .AsLocalizedDateTime intrinsic directly with the field.

I have come up with two possible options, and would like to hear input from the forum on best use, and if I am missing something, or leaving myself open for an issue down the road.

Notes:
#cDate is the #PRIM_MD.DateTime control
* work field
DEFINE Field(#wk_date) Type(*Dec) Length(8) Decimals(0)

Code: Select all

EVTROUTINE Handling(#Com_owner.Initialize)

* work date field as a date in the past
#wk_date := 20220402

* Edit is a display / input field on the Web page
#Edit := #wk_date.AsDisplayString

* Option #1 - Adjust by 1:
* #cDATE.Value := #wk_date.AsDate( ccyymmdd ).Adjust( +1 )

* OR -

* Option #2 - Load into #DateTimeX field first, then use intrinsic
#DATETIMEX := #wk_date.AsDate( CCYYMMDD )
#cDate.Value := #DATETIMEX.AsUniversalDateTime

ENDROUTINE


EVTROUTINE Handling(#Button.Click)
* this worked: option #1
* #cDATE.Value := #Edit.Value.AsDate( ccyymmdd ).Adjust( +1 )

* OR

* this also works: option #2
#DATETIMEX := #Edit.Value.AsDate( CCYYMMDD )
#cDate.Value := #DATETIMEX.AsUniversalDateTime

ENDROUTINE
Arlyn Dale
Servias LLC
adale
Posts: 210
Joined: Wed Apr 08, 2020 9:18 pm
Location: Poplarville, MS

Re: Date Control value is previous day

Post by adale »

Based upon further discussion, option #2 seems the best method at this point in time, or until enhancement requests might be made available.

* ========== *
* Updated work for forum post:
* ========== *
* Set RDMLX datetime field with the value you wish to use/display in the weblet
#DATETIMEX := #Edit.Value.AsDate( CCYYMMDD )

* Set #PRIM_MD.DateTime weblet VALUE to the selected DateTime and force .AsUniversalDateTime
* in order to not auto adjust for localized datetime calc.
#cDate.Value := #DATETIMEX.AsUniversalDateTime
Arlyn Dale
Servias LLC
KEC
Posts: 12
Joined: Fri Jun 04, 2021 4:58 pm

Re: Date Control value is previous day

Post by KEC »

This document highlights usage and impacts of DateTime. It may give some extra insights

https://www.lansa.com/downloads/support/datetime.pdf
Post Reply