NOTICE: COMMUNITY PERFORMANCE DEGRADATION
Our community is currently experiencing some performance degradation with slow page loading. Our platform SaaS vendor is working on the issue.
Highlighted
Absent Member.
Absent Member.
4114 views

Compare on a Date/Time field

Good Morning,

I am trying to put in an action that throws an error message if the implementation time is less then the (NOW) submit time. The action works, kind of. If I put any time for today it gives me the error message. So the now is working like Start of today. Does anyone know a work around for this. I don't want want an error if the date is the same but the time is greater then now.

Any suggestions would be very much appreciated.

Thank you

Darlene
0 Likes
17 Replies
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

Perhaps the issue is that NOW is date and time but your field is date only. So no, the NOW is not Start_of_today. What you want to use instead of "Now" is "Date." You can always convert a date and time to a date only by taking the Int of it as long as it's in DbLong format.

You might also need to adjust for the timezone.


' --- Calculate time zone offset from UTC
UTCOffset = DateDiff("h", dateAdd("s", Ext.DateToDBLong(Now), "1970-01-01 00:00:00"), Now)

' --- Change Action Taken Due Date to UTC
dActionTakenDueDate = Ext.DateToDBLong(DateAdd ("h", -UTCOffset, Ext.DBLongToDate(dActionTakenDueDate)))


That usually occurs when reading a date from a field entered by a user. Of course, this assumes everyone is in the same timezone. I don't know what happens if there are different timezones based on the user who filled out the field.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

I assume you are talking about a form action. If so, could you show us what your If statement looks like?
Are any of the fields Date Only fields? Are you sure it is any time of day or is it possible that it is related to a local time vs GMT time problem?
I do have a solution that works, but my solution may be more complicated then it has to be. So a little trouble shooting on your current problem would be beneficial.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

I believe the problem is that your Implementation Start Date and Time field is in Local time, but the Now might be in GMT. Anyways, here is a way to work around it:

Add a date/time field to your primary table, call it "Local Now" (place in the Hidden section and don't allow reporting). On the transition(s) that use this form, move the field to the Standard field section and set the default value to Now.

Add this new field to the form, but you can hide it with a Submit form action (it needs to be on the form though).

Then change your If comparison for the date/time field part to "a javascript evaluates to true of false condition" comparison and set the JavaScript to (you might need to change to the correct dbname for your Implementation field):
var dtNow, dtStart;

dtNow = GetFieldValue( "LOCAL_NOW" );

dtStart = GetFieldValue( "IMPLEMENTATION_START_DATE_TIME" );

// Okay if date is in future
return ( dtStart > dtNow );
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

Did you change the database name of the field within the script to match your database name? In the script, True is the valid response. Is Change Type field set to Standard?
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

Don't hide the new "Local Now" field and make sure it has the current date/time within it.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

Hi Lynn,

Yes I am talking about an action. Here is the way I wrote it.

When
this for is loaded
Or Implementation Start Date and Time field changes value

If Change Type field in Standard
and
Implementation Start Date and Time field Now
then
make Implementation Start Date and Time field valid


Thank you

Darlene
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

Gerard

Thank you for your response.

Are you saying to break out the date time field into separate fields? All of my users are in the same timezone.

Thank you for the info on adjusting the timezone. Can you tell where is go to do that?

Thank you

Darlene
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

No, you wouldn't break them out in separate fields. Is this an AppScript, JavaScript, or something else? Can you post what you've done so far?
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

Lynn,

Thank you so much!

I am going to give that a try right now!

Thank you again!

Darlene
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

Couldn't you use the adjustedUTCTime formula in the "Using the tzOffset Variable" example in the help to get the adjusted dtNow? I haven't tested it, but something like:

function getLocalDateTime()
{
var now = new Date();
var adjustedUTCTime = now.getTime() + (tzOffset * 1000) + (now.getTimezoneOffset() * 60 * 1000);
var adjustedDate = new Date(adjustedUTCTime);
return adjustedDate;
}
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Compare on a Date/Time field

Lynn,

I did the following and it’s not letting any time go thru.

I created a new field Local now, and put it on the forms.

Here is my rule now.

When form is loaded
Or Implementation Start Date and Time field changes

If Change type filed is in Standard
And
Javascript var evaluates to True

Then
Display error message……………
Clear Implementation Start Date and Time field
Make Implementation Start Date and Time field required

Else If
Java script evaluates to False
Then
Make Implementation Start Date and Time field valid
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.