FoxPro Programming
Converting DATE/TIME based on Time Zones
Gravatar is a globally recognized avatar based on your email address. Converting DATE/TIME based on Time Zones
  Roy Miller
  All
  Jun 8, 2017 @ 07:19pm

Listmates,

I need to convert times for clients, the file server time is set to central. When we auto add a date for the client, it uses the servers bios clock. Should the user profile be set to Pacific, I want to convert it for them. Has anybody tackled this issue before?

Thanks in Advance

Roy

Gravatar is a globally recognized avatar based on your email address. re: Converting DATE/TIME based on Time Zones
  Rick Strahl
  Roy Miller
  Jun 9, 2017 @ 01:02pm

This is not trivial to do especially in FoxPro since it has no native support for UTC dates and time zone conversions.

The generally accepted way to do this is to store all dates in UTC format in the database and then perform whatever adjustments you need to to display the dates to users.

Web Connection provides a number of functions that can help with that, but it's not quite everything you need:

In fact, I looked at FromUtcTime() and realized that it would greatly benefit from having a timezone offset attached to it so you can adjust for a given offset.

The adjusted function looks like this:

************************************************************************
*  FromUtcTime
****************************************
***  Function: Returns local time from UTC Time
***    Assume:
***      Pass: ltTime          - UTC Time
***            lnOffsetMinutes - optional offset minutes 
***    Return:
************************************************************************
FUNCTION FromUtcTime(ltTime, lnOffsetMinutes)
LOCAL lnOffset

IF VARTYPE(lnOffsetMinutes) # "N"
   lnOffset = GetTimeZone() * 60	
ELSE
   lnOffset = lnOffsetMinutes * 60
ENDIF

RETURN ltTime - lnOffset
ENDFUNC
*   FromUtcTime

Using these functions you can store UTC dates in the database, and then adjust dates for a user setting (or local time) stored with each user.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Converting DATE/TIME based on Time Zones
  Roy Miller
  Roy Miller
  Jun 11, 2017 @ 02:54pm

Thanks Rick ... I'll give it a go

© 1996-2024