I’ve this desk:
kind Desk struct {
Date time.Time `gorm:"column:date;kind:datetime;default:current_timestamp;not null"`
}
However it’s saved on this format:2023-10-25 23:36:29.4928236-05:00
How do I get gorm to retailer it this manner?10-25-2023 23:36:29.4928236-05:00
Sqlite all the time retailer dates as “YYYY-MM-DD HH:MM:SS”. So, the issue, i feel, is the best way to present the datetime in a specific format you need so you should use time.Format to use the sample you need.
In order that signifies that if I wish to retailer in my most popular format then I need to use the textual content kind and never datetime, appropriate?
I believed gorm would do this for me with a customized datatype.
I do know I’m late to this query…
How the database is storing the information must be irrelevant, in my humble opinion. Any software that makes use of the information are accountable for displaying it within the appropriate format for the particular person, and that features no matter device you might be utilizing to browse the database (MySQL Workbench, SSMS,…) in addition to your program.
So, in brief, I feel that storing a date in a string is a very unhealthy concept…as a substitute it is best to deal with the best way to DISPLAY the date appropriately, not the best way to STORE the date appropriately.
1 Like
the Date just isn’t saved as a string, that’s simply they default format. It’s best to all the time used ISO8601 FULL on the backend and solely DISPLAY the Date or TimeStamp in a distinct LOCALE on the entrance finish.
Belief me, you DO NOT wish to retailer the Dates as that tousled conventional US format within the backend.
The default format kinds naturally and is UNAMBIGUOUS about what fields are what.