Convert from Server time to local

I have a database on XC and the time stamps are GMT. I was told they can’t change that.

So does anybody have a function to set the time to our local US Central (+6) from GMT?

perhaps use WebSession.GMTOffset? It seems to be precisely what you are looking for.

WebSession.GMTOffset is Read-Only. Its purpose is to allow you to convert dates so they display correctly on each user’s browser, no matter where they are in the world.[quote=477825:@Richard Albrecht]So does anybody have a function to set the time to our local US Central (+6) from GMT?[/quote]
Pull a date from the database, apply the value of Session.GMTOffset and the date should now be in user local time.

But I don’t want the user local time, I want it to be central US, Chicago.

Try this

Var LocalDate As New DateTime(GMTDate.SecondsFrom1970, New TimeZone(6 * 60 * 60))

But that will not take into a count daylight savings time?

Are you using Date, Xojo.Core.Date or DateTime?

Use the timezone name then.

Var Local As New DateTime(GMT, New TimeZone("America/Mexico_City"))

Using DateTime.

@Wayne Golding Where is ther a list of time zones? I need Central time Chicago.

Wayne, what’s Var?

API 2.0 Var replaces Dim

I just tried to compile under 1029 3.1

Got this error, GMT Highlighted:

WebPage1.btnTime.Action, line 1
This item does not exist
Var Local As New DateTime(GMT, New TimeZone(“America/Mexico_City”))

Here’s my code:

[code]Var Local As New DateTime(GMT, New TimeZone(“America/Mexico_City”))

Var Server As New DateTime

txtServerTime.Text = Server.SQLDateTime

txtChicagoTime.Text = Local.SQLDateTime
[/code]

Got this error also:

WebPage1.btnTime.Action, line 3
There is more than one method with this name but this does not match any of the available signatures.
Var Server As New DateTime

Read https://documentation.xojo.com/api/data_types/datetime.html
when you use ‘As New DateTime’ you need to use one of the constructors and you are not using one.

To make ‘As New DateTime(GMT, TimeZone)’ to work, GMT should have SecondsFrom1970
Try this:

Var server_date As DateTime = DateTime.Now Var local_date As New DateTime(server_date.SecondsFrom1970, New TimeZone("America/Chicago"))

If you read https://documentation.xojo.com/api/os/timezone.html you can see the link to the list of time zones.

Now getting
WebPage1.btnTime.Action, line 1
This item does not exist
Var Local As New DateTime(server_date.SecondsFrom1970, New TimeZone(“America/Chicago”))

WebPage1.btnTime.Action, line 1
Type “Int32” has no member named “SecondsFrom1970”
Var Local As New DateTime(server_date.SecondsFrom1970, New TimeZone(“America/Chicago”))

WebPage1.btnTime.Action, line 3
There is no class with this name
Var Server As New DateTime.now

Do I need to do something to reference API 2?

You can get help from Xojo IDE to find what is wrong with your code.

This doesn’t exist in Xojo:

Var Server As New DateTime.now

it should be:

Var Server As DateTime = DateTime.Now

If you want to use Server instead of server_date as a variable, then you need to put that in the correct order.
You are getting error in line 1, because you are not defining server_date before using it

In your case, if you want to use Server and Local then your code should be:

Var Server As DateTime = DateTime.Now Var Local As New DateTime(Server.SecondsFrom1970, New TimeZone("America/Chicago"))

Thank you that did it. Now if it works when DST kicks in I’ll be happy!