Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lord_Gordon's avatar

SQL: Converting a number to date format then assigning it to a table field

Hello everyone, I have a doubt:

  • I am working in SQL, in a table called 'results'.

  • I have this number: 20201109000000 in a column called 'value' in the 'results' table

  • I must convert the number to a date format and then move from the 'value' column to the 'descrip' column in the 'results' table

  • To do this I must use 'UPDATE' to make the change and 'FORMAT' to change the number to a date.

Kind regards

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

To convert the number to a date format and move it from the 'value' column to the 'descrip' column in the 'results' table, you can use the following SQL query:

UPDATE results SET descrip = FORMAT(CAST(value AS DATETIME), 'yyyy-MM-dd')

This query uses the CAST function to convert the 'value' column to a DATETIME data type, and then the FORMAT function to format the date as 'yyyy-MM-dd'. The result is then assigned to the 'descrip' column using the UPDATE statement.

Note that the specific date format used in the FORMAT function can be adjusted to match your desired output format.

1 like

Please or to participate in this conversation.