slanoss Posted January 18, 2015 Share Posted January 18, 2015 I insert a time value using the following code $ti= ( !empty($_POST['time']) ) ? "'{$_POST['time']}'" : 'NULL'; I want to insert a second time value into a differen column which would be the same time minus 1 hour something along the lines of : $ti2= ( !empty($_POST['time']) ) ? "'{$_POST['time'] -1 hour}'" : 'NULL'; What would be the correct way to do it Quote Link to comment https://forums.phpfreaks.com/topic/294032-insert-time-minus-one-hour/ Share on other sites More sharing options...
Barand Posted January 18, 2015 Share Posted January 18, 2015 INSERT INTO tablename (col1, col2) VALUES ('$t1', '$t1' - INTERVAL 1 HOUR) Quote Link to comment https://forums.phpfreaks.com/topic/294032-insert-time-minus-one-hour/#findComment-1503333 Share on other sites More sharing options...
slanoss Posted January 18, 2015 Author Share Posted January 18, 2015 In my original I have Insert into table1 (time) values ($ti); which works correctly (no quotes round $ti) I have put insert into table1 (time, time2) values ($ti, $ti - interval 1 hour ); But it doesn't work, NULL is inserted into time2 not time minus 1 hour Any ideas , thanks. Quote Link to comment https://forums.phpfreaks.com/topic/294032-insert-time-minus-one-hour/#findComment-1503335 Share on other sites More sharing options...
Barand Posted January 18, 2015 Share Posted January 18, 2015 So your your times are not in TIME format then? What format are they? Quote Link to comment https://forums.phpfreaks.com/topic/294032-insert-time-minus-one-hour/#findComment-1503337 Share on other sites More sharing options...
Barand Posted January 19, 2015 Share Posted January 19, 2015 Looks like INTERVAL works only on DATETIME and not TIME columns, so needs SUBTIME() INSERT INTO test (timecol1, timecol2) VALUES ('03:00', SUBTIME('03:00', '1:00')); Quote Link to comment https://forums.phpfreaks.com/topic/294032-insert-time-minus-one-hour/#findComment-1503340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.