Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding One Hour In DATE_FORMAT

Tags:

mysql

Hi Friends i am new one to MySQL I want display my date time format as like the following that is one hour to next hour from DATE_FORMAT() function using MySQL

2015-01-21 12:TO:01:AM

To display for above format i am using the following MySQL query

SELECT DATE_FORMAT(date_time,'%Y-%m-%d %h:TO:(%h+1):%p') from table

but i am getting the following output

2015-01-21 12:TO:(12+1):AM

please give me your guidance

like image 686
rmrps Avatar asked Oct 20 '25 11:10

rmrps


1 Answers

You need to add an hour to the date, and format that time separately so you can concatenate the two strings.

SELECT CONCAT(DATE_FORMAT(date_time, '%Y-%m-%d %h:TO:'),
              DATE_FORMAT(DATE_ADD(date_time, interval 1 hour), '%h'),
              DATE_FORMAT(date_time, ':%p'))
FROM table
like image 154
Barmar Avatar answered Oct 23 '25 01:10

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!