I'm looking for the equivalent of MySQL now(). Any format is fine.
Asked
Active
Viewed 4,220 times
4
-
Hint: `getdate()`, `current_timestamp`. – Gordon Linoff Apr 12 '17 at 20:10
2 Answers
4
You should create a User Defined Function (UDF) like this.
function now() {
return new Date();
}
You would call it like this:
SELECT udf.now(), c.date, c.id FROM c WHERE c.date < udf.now()

Larry Maccherone
- 9,393
- 3
- 27
- 43
-
2your answer worked perfectly. Maybe you should explain the UDF in a little bit more details. I am very new to Azure Cosmos and did not get the first sentence at once. "You should create an User Defined Function like this" Was more appropriate for a begniner like me. Just a hint ... – achahbar Jun 24 '19 at 08:01
3
As of the end of 2020, there are 2 functions to get current date/time in Cosmos DB:
SELECT
GetCurrentDateTime() AS utc_datetime_iso_8601,
GetCurrentTimestamp() AS timestamp_with_milliseconds
returns
[
{
"utc_datetime_iso_8601": "2020-12-25T22:56:27.3453234Z",
"timestamp_with_milliseconds": 1608936987345
}
]

Max Ivanov
- 5,695
- 38
- 52