FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

For more details, review the migration guide. Contact support@fauna.com with any questions.

ToTime

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

ToTime( value )
to_time( value )
ToTime( value )
ToTime( value )
ToTime( value )

Description

The ToTime function converts a value to a timestamp, if possible.

Attempting to convert a value to a timestamp which has no timestamp representation results in an "invalid argument" error.

Parameters

Parameter Type Definition and Requirements

value

Any

The value to attempt to convert to a Timestamp.

Returns

A Timestamp created by interpreting value.

Examples

The following query converts the string "2015-02-20T06:30:00Z" to a timestamp:

client.query(
  q.ToTime('2020-07-06T12:34:56.789Z')
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
Time("2020-07-06T12:34:56.789Z")
result = client.query(
  q.to_time('2015-02-20T06:30:00Z')
)
print(result)
FaunaTime('2015-02-20T06:30:00Z')
result, err := client.Query(
	f.ToTime("2015-02-20T06:30:00Z"))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
{0 63560010600 <nil>}
try
{
    Value result = await client.Query(
        ToTime("2015-02-20T06:30:00Z")
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
FaunaTime(2015-02-20T06:30:00Z)
ToTime('2020-07-06T12:34:56.789Z')
Time("2020-07-06T12:34:56.789Z")
Query metrics:
  •    bytesIn:  38

  •   bytesOut:  47

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 2ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!