DateConvert

Converts local time to Coordinated Universal Time (UTC), or UTC to local time.

The function uses the daylight savings settings in the executing computer to compute daylight savings time, if required.

Method Signature

DateConvert(conversionType=[string], date=[any])

Arguments

Argument
Type
Required
Description
Default

conversionType

string

true

The conversion type. Valid values are "utc2Local" and "local2Utc".

date

any

true

The date to convert.

Examples

Converting Local to UTC

Run Example

utc_datetime = dateConvert( "local2Utc", now() );

Result: {ts '2025-05-27 05:12:10'}

Converting UTC to Local

This example makes sense only if your server time is UTC. now() uses your server settings when creating a datetime object.

Run Example

local_datetime = dateConvert( "utc2Local", now() );

Result: {ts '2025-05-26 22:12:10'}

Additional Examples

Run Example

writeDump( DateConvert( "Local2utc", "{ts '2006-01-26 02:00:00'}" ) );
writeDump( DateConvert( "utc2Local", now() ) );

Last updated

Was this helpful?