Suppose I pull a field from the database, a timestamp field.
How do I get the Unix Timestamp, 1 month in the future, from that timestamp field?
My brain is a bit tired, so I need a bit of a re-jogging.
One month = 2,419,200 for 28-day months, 2,505,600 for 29-day months, 2,592,000 for 30-day months and 2,678,400 for 31-day months. One year = 31,536,000 in UNIX time.
If you'd like to calculate the difference between the timestamps in seconds, multiply the decimal difference in days by the number of seconds in a day, which equals 24 * 60 * 60 = 86400 , or the product of the number of hours in a day, the number of minutes in an hour, and the number of seconds in a minute.
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC. One of the primary benefits of using Unix time is that it can be represented as an integer making it easier to parse and use across different systems.
$newDate = strtotime('+1 month',$startDate);
Using strtotime() you can pass it '+1 month' to add a context sensitive month.
I would use the strtotime()
function, to add +1 month
to your timestamp :
$future = strtotime('+1 month', $current_time);
With strtotime()
, you don't have to think yourself about stuff like "some month avec 30 days, and others have 31", or "february sometimes has 28 days and sometimes 29".
After all, adding one month to a date is a bit harder that adding 30*24*3600 seconds...
You could also work with the DateTime
class, and methods such as DateTime::modify()
or DateTime::add()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With