Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSonny Österlund
6,578 PointsMySQL how to add a correct end time into its own table column
Hi I have a Q Im buildning a database and are trying everything out how to make it work and got into a little pickle I buildning a online booking system and have a time date for starting and would like to add a end time as well and use the start time as a reference and add 1 hour I am using phpMyAdmin if that makes a diffrence
I might be totaly off but
PLZ Help if you can
INSERT INTO booked (barber_id, customer_id, start_time, end_time)
VALUES (5, LAST_INSERT_ID(), '2016-03-18 15:00:00', SELECT DATE_ADD('2016-03-18 15:00:00', INTERVAL 1 HOUR);
Sonny
2 Answers
Brandon McClelland
4,645 PointsmySQl has built in functions for adding dates or time to an existing date, so you could just use ADDTIME(date1, 1:0:0.0) but I'm not sure why if you're already directly adding the start date you wouldn't do the same for the end date like:
VALUES (5, LAST_INSERT_ID(), '2016-03-18 15:00:00', '2016-03-18 16:00:00');
Sonny Österlund
6,578 PointsJust wanted to say thank you for your help If anyone want to tknow I ended up using this code:
$inserted_time = $_POST['time'];
$bookedtime = strtotime($inserted_time) + 60*60;
$endtime = date('H:i:s', $bookedtime);