Skip to Content
Menu
This question has been flagged
3 Replies
3037 Views

I have a project using React Native to FE and Odoo to BE. I'm calling field Date from odoo by Graphql, and when I test in Graphiql:  "dateOfBirth": 738733". I want to convert that day to 'dd/mm/yy' in React Native (DateTimePicker).


The expected result: 08/01/2023 (mm/dd/yyyy)

Avatar
Discard
Best Answer

How do implement dynamic form in react native using odoo? please help

Avatar
Discard
Author Best Answer

Thanks for your help. I tried, but the result was not as expected. 

My result: 09/01/1970 (mm/dd/yyyy). 

I used moment in React to format before, but the result was 09/01/1970 (like this way). 

Please.


Avatar
Discard

If you're getting the Unix timestamp as 738733 from Odoo GraphQL and you expect it to represent 08/01/2023 (August 1, 2023), then there seems to be a discrepancy in the timestamps you're receiving. The provided timestamp and the expected date don't match.

Make sure that you are correctly receiving and processing the timestamp from Odoo's GraphQL response. If the timestamp is indeed meant to represent 08/01/2023, then you need to verify how the timestamp is generated and transmitted in your Odoo setup.

For reference, if you have a valid Unix timestamp for 08/01/2023, it would be a much larger number than 738733, typically in the order of billions (seconds since January 1, 1970). Double-check the data you are receiving and consider checking with the Odoo API or your backend to ensure that the correct timestamp is being sent to your React Native application.

Author

I checked my field date_of_birth and it was 'field.Date'. Then I changed to 'field.Datetime' and used your way to convert the timestamp, and it's working.

Thanks a lot.

Best Answer

try this way:
// Assuming date of birth is the timestamp received from Odoo

const timestamp = 738733; // Replace this with the actual timestamp


// Convert the timestamp to a JavaScript Date object

const date = new Date(timestamp * 1000); // Odoo timestamp is in seconds, so convert to milliseconds


// Format the date as 'dd/mm/yy'

const formattedDate = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear().toString().slice(-2)}`;


console.log(formattedDate); // Output: "18/02/23"

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 19
9397
1
May 16
4231
2
Mar 23
10306
0
Nov 22
2020
0
Sep 21
2576