Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save Jalali(Hijri shamsi) datetime in database in django

I have a Django project, and I want to save created_at datetime in the database. I generate datetime.now with jdatetime (or Khayyam) python package and try to save this in DateTimeField. But sometimes it raises error because the Gregorian(miladi) date of the entry does not exist. what can I do about this?

like image 631
Kasra Najafi Avatar asked Oct 21 '25 17:10

Kasra Najafi


1 Answers

In my idea, you can save two model fields. One is DateTimeField contains gregorian datetime, and another one, CharField contains converted Jalali to a String value and save it. The DateTimeField for functionality, e.g., filter between to datetime. The StringField for representing in response(without overload).

like image 180
mahyar Avatar answered Oct 23 '25 07:10

mahyar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!