1

I am sending the DateTime field from Java to documentdb/SQL API to cosmos db . but it is saving the datetime as a number in documentdb , if i parse my datetime value to string then documentdb is showing correctly in string form , but i need it in datetime format in documentdb/SQL API .

What's the best practise to save datetime value in documentdb without parsing it to string? What is the value of the date field in the documentdb collection if i not parse my datetime field to string ? for i.e "loggedAt": 1554207604392 is showing this number in documentdb . Can anyone please help me on this .

Document Db Item, highlighted field is the datetime which i am sending from java

1 Answers1

0

What is the value of the date field in the documentdb collection if i not parse my datetime field to string ?

The number is representing the number of elapsed seconds since January 1, 1970 which matches your datatime as Unix timestamps. Azure Cosmos DB's internal Timestamp (_ts) property follows this approach. You could refer to this document for details.

enter image description here

What's the best practise to save datetime value in documentdb without parsing it to string?

From this feedback case,ms doesn't support native datetime type data.In this blog,the datetime data still was treated as String or Number.

As for unix timestamp query operations,You could follow my previous case :Convert TimeScript to Date in Azure CosmosDB SQL Query to convert unix timestamp to datetime by using UDF. Or get some clues from this case:Date Between Query in Cosmos DB

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • I have attached the response of azure document db , i am talking about the custom datetime field which i am sending from java to documentdb , you are refering to the timestamp which azure marked to document db while inserting data . – Rizwan Saleem Apr 03 '19 at 04:28
  • @RizwanSaleem But based on the feedback case in my answer, cosmos db can't accept datetime type so far,you have to convert the datetime to string or unix timestamp number so that it could be inserted into database. – Jay Gong Apr 03 '19 at 04:43
  • @RizwanSaleem So, you still want to save native datetime into cosmos db database from java sdk, am i misunderstanding? – Jay Gong Apr 03 '19 at 05:07
  • @RizwanSaleem So,any progress?Rizwan. – Jay Gong Apr 04 '19 at 01:06
  • @RizwanSaleem Hi,does my answer helps you? – Jay Gong Apr 08 '19 at 01:47