ALERT! The community will be read-only on April 19, 8am Pacific as the migration begins. Read more for important details.
ALERT! The community will be read-only on April 19, 8am Pacific as the migration begins.Read more for important details.
Commander
Commander
3043 views

Date Field being localized?

Hello All,

I have a date field that is only the Date (e.g. 1/27/2016). I'm pulling this date via a script (see below) and also copying the value of the field to our description field.


If Not Shell.Item.GetFieldValue( date_SRC, reqDate ) then
' Error finding the field or reading from it
Call Ext.LogErrorMsg( "Cannot read from field " & QUOTE & date_SRC & QUOTE )
End If


But when I then convert to a non numeric date back into a date. then print it out to our work notes field:

 reqDate = ext.DBLongToDate(reqDate)

If Not Shell.Item.SetFieldValue (FLDNAME_DEST, (reqDate)) Then
'Error finding the field or writing to it
Call Ext.LogErrorMsg( "Cannot write to field " & QUOTE & FLDNAME_DEST & QUOTE )
End If




The date goes from being 1/27/2016 to my localized date/time (1/26/2016 7:00:00 PM)...


any ideas on how to get this to display in GMT so it has the right date?
0 Likes
4 Replies
Commander
Commander

FYI I'm still not sure how to get around the localization... when I pull out the DBLong and convert it to a date it goes from 1/27/2016 00:00:00 GMT to 1/26/2016 19:00:00 EST; but since I know that the localization seems to happen based on the server's timezone (e.g. Eastern Standard Time GMT - 5) I'm compensating by adding +1 to the datetime to get to the right date, then convert it to a vbshortDate to strip out the time. Not ideal but it works. I'm still curious if anyone knows why it uses the server's timezone or how to override it to stick with GMT
0 Likes
Absent Member.
Absent Member.

Give these AppScript functions a try:

function getUTCOffset()

' Calculates the offset between the current Serena user's timezone and the database (UTC) time
getUTCOffset = dateDiff("h", now, dateAdd("s", ext.DateToDBLong(now), "1970-01-01 00:00:00"))
end function

function localDateToUTC(dateObj)
' Converts a date object to UTC (database time) by adding the number of hours offset from the current Timezone to UTC
localDateToUTC = dateAdd("h", getUTCOffset(), dateObj)
end function

function UTCDateToLocal(dateObj)
' Converts a date object from UTC (database time) to the current timezone by subtracting the number of hours offset difference
UTCDateToLocal = dateAdd("h", (getUTCOffset() * -1), dateObj)
end function
0 Likes
Absent Member.
Absent Member.

FYI hard-coding offsets is a bad idea unless you live in Arizona as it's guaranteed to break twice a year.
0 Likes
Commander
Commander

Jeff - in regards to hard coding, normally I would agree with you, but even with timezone switches (e.g. EST to EDT and vice versa), the conversion would still only be an hour off... and since in this case I really just care about getting the date value, I can just add a day to get it to the right date.
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.