How can I change the date and year format in SQL? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I change the date and year format in SQL?

30th Oct 2019, 8:57 PM
Ali Altamash Awan
Ali Altamash Awan - avatar
3 Answers
0
what you are trying to do is probably change a stored datetime value to a format you prefer for your locale. what you need to realize is you don't have to store a datetime value in your preferred locale format. you can store it as a Unix timestamp value (seconds since epoch) and then when you pull date values from your database (SELECT query) you can usually use a function like DATE to format the value however you like at that time. look at DATE function and you will probably see what you want. this is for sqlite: https://www.sqlite.org/lang_datefunc.html
30th Oct 2019, 11:31 PM
Nathan Stanley
Nathan Stanley - avatar
0
The date or datetime is stored in the database in a uniform manner (doesn't depend on locale). The way it is displayed to you when you query, is however dependent on the language and location setting of the database or the client program itself. You can format dates to your liking also by converting to character with a specific format string code, but the way is specific to the db engine. eg. in Oracle database it is like TO_CHAR(your_date, 'YYYY/MM/DD')
31st Oct 2019, 10:18 AM
Tibor Santa
Tibor Santa - avatar