I have the following query:
INSERT INTO table (a, b, c) VALUES (NOW(), NOW() + INTERVAL 14 DAY,?)
For a and b I’m using timestamps while b is timestamp a, just added plus 14 days.
The problem I got is that I need c later on a login script where further queries will be happen when c will be downcounted to zero.
Therefore, I thought it would be the best way to find a variable which exactly calculates the difference between a and b like
b - a = c
and such a variable will be inserted into the db.
My problem is, that I now have 2 timestamps from the value part which I dont know how to use up to this point. I could get them via fetch_assoc etc. to handle them. But before that, I thought there is maybe an easier way to reach my goal?
If you want to have
cto be an integer and the difference betweenaandbthen you can use unix_timestamps (that’s the seconds elapsed since 1970-01-01).To convert such an integer value back to a timestamp you can use the function
FROM_UNIXTIME()You can find more info here.