Skip to content
Advertisement

Extract Numeric Date Value from short Date Format in SQL

I am trying to convert short date format to numeric date format in SQL.

Here are the dates I am trying to convert: 16-Mar-20 18-Mar-20 12-Mar-20

I have seen many methods to re-format dates based on numeric numbers but I am working with a dataset which has varied date-types. To ensure smoothness, I wanted to know what’s the way to convert these numbers to numeric date. Note that even if I extract the day month and year individually I could multiply them with respective values to get the dates. Here’s what I have done: (Although I have tried multiple things but this is the one which has yielded me the closest result, Note that my end goal is to convert the date into numeric value)

Here Start Date is formatted in the way I have mentioned above. (14-Mar-20).

Advertisement

Answer

UNIX_TIMESTAMP is what you need, but first you have do transform your data to a Date

With

You get

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement