Home > Software design >  How to extract date and hour only from MySQL?
How to extract date and hour only from MySQL?

Time:07-13

I have this column in MySQL table:

Date
2022-07-13 07:01:20

I want to extract this column to get this (the date and hour only):

2022-07-13 07

Any help is appreciated thanks!

This date column is in the form of timestamp

CodePudding user response:

Apparently timestamp is a string so i can use substring.

CodePudding user response:

To select the date and hour from that format first you have to take the substring using SUBSTRING() the convert to datetime format using STR_TO_DATE() you can take the specific date using SELECT CONVERT(date, your_date_time); then extract the hour to add it in there SELECT HOUR()
you can then convert back to a string or use it that way

  • Related