I have datetime column which is in this format YYYY-MM-DD HH:mm:ss.
But in my php form for updating this data I have created 2 separate fields one is for DATEpart and one is for TIMEpart.
There is no problem to receive/load these values into my php form from table using:
RIGHT(datetime,8) for TIMEpart or for DATEpart LEFT(datetime,10)
Problem is I am not able to update also only that part of data. If I am attempting to update with TIMEpart it will try to update first 8 characters of datetime instead of attempting to update last 8 character. Problem is I do not know how to tell the program to do so, I know that it needs to be defined into my sql query.
$query3=mysqli_query($db,"update LISTS set datetime=LEFT(datetime,10),
datetime=RIGHT(datetime,8) where id='$id'");
I am new into SQL and PHP. I have this already working by having 2 separate columns but I would like to simplify sql table if possible.
Thanks in advance.
I think you want to use addtime()
:
update lists
set datetime = addtime(@date, @time)
where id = @id;
Learn to use proper parameterized queries rather than munging the query string with user input values. Your approach is likely to lead to inexplicable syntax errors and makes the code vulnerable to SQL injection.