1DATE_FORMAT(date, format)
2-- E.g.
3SELECT DATE_FORMAT(dateField, '%m/%d/%Y') FROM TableName;
4-- See https://www.mysqltutorial.org/mysql-date_format/ for available formats
1DATE_FORMAT(NOW(),'%M %e, %Y @ %h:%i %p')
2#Format is 'June 10, 2014 @ 06:52 PM'
1-- Converts 'dd.mm.yyyy' to date (my_date_col is VARCHAR)
2SELECT STR_TO_DATE(my_date_col,'%d.%m.%Y') AS my_strdate FROM my_table;
3-- Converts 'dd.mm.yyyy' to 'YYYY-MM-DD'
4SELECT DATE_FORMAT(STR_TO_DATE(my_date_col,'%d.%m.%Y'), '%Y-%m-%d') AS my_strdate
5 FROM my_table;
1-- use DATE_FORMAT with %H %i
2-- SELECT DATE_FORMAT(MemberBookFacility.time, '%H:%i')
3"45": "09:00",
4"24": "10:00",
5"42": "11:00",
6"48": "12:00",
7
8-- ONcakephp must use below format
9$this->virtualFields['time'] = "DATE_FORMAT(MemberBookFacility.time, '%H:%i')"; // using this for use concat
10
11 return $this->find('list', array(
12 'conditions' => $conditions,
13 'fields' => array(
14 'MemberBookFacility.id',
15 'time',
16 ),
17 'order' => array(
18 'MemberBookFacility.time ASC',
19 ),
20 ));
1use \Datetime;
2
3$now = new DateTime();
4echo $now->format('Y-m-d H:i:s'); // MySQL datetime format
5echo $now->getTimestamp(); // Unix Timestamp -- Since PHP 5.3
6
1DECLARE df VARCHAR(20);
2DECLARE dt VARCHAR(20);
3
4SET df = DATE_FORMAT(_Datefrom,'%Y-%m-%d 00:00:00');
5SET dt = DATE_FORMAT(_DateTo,'%Y-%m-%d 23:59:59');