1

I want to calculate EXACT past 30 days time period in php from now (for example 30 aug 14 23:06) to 30 days back (for example 1 aug 14 23:06). I wrote this where current datetime goes in $d1 and past 30 days datetime goes in $d2 but somehow i am not getting correct results. Any idea?

$url=$row["url"];
$pageid=getPageID($url);
$date=date('y-m-d g:i');
$d1=strtotime($date);
$d2=date(strtotime('today - 30 days'));

Thanks

3
Contributors
2
Replies
24
Views
3 Years
Discussion Span
Last Post by kaleemullah360
0

The easiest and good method to claculate exact date time is TIMESTAMP.
claculate time stamp of first date and second date then subtrac them that will be your required date in the form of time TIMESTAMP cgange it to human read able form using TIMESTAMP functions

<?php 
//Our dates
$date1 = "2013-03-01 19:12:45";
$date2 = "2014-03-01 06:37:04";

//Convert them to timestamps.
$date1Timestamp = strtotime($date1);
$date2Timestamp = strtotime($date2);

//Calculate the difference.
$difference = $date2Timestamp - $date1Timestamp;

echo $difference;

?>

Reference

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.