How to convert date format from html to sql using php? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to convert date format from html to sql using php?

I want to convert only the date, not date and timestamp, but if I use the 'strtodate' function it backdates the date i selected to 1970. pls help. my code is below. if ( isset( $_POST['book_app'] ) ) { $patient_id = $_POST['patient_id']; $appointment_date = $_POST['appointment_date']; $doctor = $_POST['doctor']; $appointment_time_starts = $_POST['appointment_time_starts']; $appointment_time_ends = $_POST['appointment_time_ends']; $query = "insert into doctorapp (patient_id, appointment_date, doctor, appointment_time_starts, appointment_time_ends) values('$patient_id', '$appointment_date', '$doctor', 'appointment_time_starts', 'appointment_time_ends') ";

25th Dec 2019, 3:59 AM
DOJ
DOJ - avatar
4 Answers
+ 2
uhm, functions usually expect to work with a unix timestamp which is equal to seconds passed since 01.01.1970 00:00:00. obviously you cannot create a timestamp that doesn't contain the hours, minutes and seconds, although you can simply use midnight. you can create a unix timestamp using mkdate(). if you don't need hours/minutes/seconds, you just don't include them when calling date(). example: <?php $time = mktime(0, 0, 0, 12, 27, 2019); echo date("d.m.Y H:i:s", $time); ?>
27th Dec 2019, 8:01 AM
grdr
+ 1
you can use the date () function by passing the date in SQL format as a parameter: year in 4 digits / month / day
27th Dec 2019, 9:20 PM
Moustapha Dieye
Moustapha Dieye  - avatar
+ 1
thanks, really helpful! I finally got it.
28th Dec 2019, 5:06 AM
DOJ
DOJ - avatar
0
OK thanks a lot
28th Dec 2019, 8:55 PM
Moustapha Dieye
Moustapha Dieye  - avatar