ToDate

ToDate( value )
ToDate( value )
ToDate( value )
ToDate( value )
to_date( 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:

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)
result, err := client.Query(
	f.ToDate("2018-06-06"))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
{0 63663840000 <nil>}
System.out.println(
    client.query(
        ToDate(Value("2018-06-06"))
    ).get());
2018-06-06
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
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!