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
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');
1DATE : stocke une date au format AAAA-MM-JJ (Année-Mois-Jour) ;
2
3TIME : stocke un moment au format HH:MM:SS (Heures:Minutes:Secondes) ;
4
5DATETIME : stocke la combinaison d'une date et d'un moment de la journée au format AAAA-MM-JJ HH:MM:SS. Ce type de champ est donc plus précis ;
6
7TIMESTAMP : stocke le nombre de secondes passées depuis le 1er janvier 1970 à 00 h 00 min 00 s ;
8
9YEAR : stocke une année, soit au format AA, soit au format AAAA.