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.

ToDate

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

ToDate( value )
to_date( value )
ToDate( value )
ToDate( value )
ToDate( value )

Description

The ToDate function converts a value to a date type, if possible.

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

Parameters

Parameter Type Definition and Requirements

value

Any

The value to attempt to convert to a Date.

Returns

A Date created by converting from value.

Examples

The following query converts the string "2018-06-06" to a date:

client.query(
  q.ToDate('2018-06-06')
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
Date("2018-06-06")
result = client.query(
  q.to_date("2018-06-06")
)
print(result)
2018-06-06
result, err := client.Query(
	f.ToDate("2018-06-06"))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
{0 63663840000 <nil>}
try
{
    Value result = await client.Query(
        ToDate("2018-06-06")
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
FaunaDate(2018-06-06 12:00:00 AM)
ToDate('2018-06-06')
Date("2018-06-06")
Query metrics:
  •    bytesIn:  24

  •   bytesOut:  35

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 4ms

  •    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!