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

Argument 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', err))
Date("2018-06-06")
result = client.query(
  q.to_date("2018-06-06")
)
print(result)
2018-06-06
try {
  println(Await.result(
  client.query(
    ToDate("2018-06-06")
  ),
  5.seconds
))} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
2018-06-06

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!