/    Sign up×
Community /Pin to ProfileBookmark

function to calculate if date range is Invalid

I have 2 date selector text boxes passing the values to my php page. I thought I could turn the vales into unix time stand and then disregard any positive or negative values. This works on most dates, but when I was testing it, It did not turn “02-19-2008 00:00:00” into a unix time stamp, so therefore it did not do the calculation need to tell if rage is valid. Here is what I had…

$startdate = strtotime($Psdate);
$enddate = strtotime($Pedate);
$datediff = $enddate – $startdate;
//test to see if these even are valid date
if (checkdate($smon,$sday,$syea) && checkdate($emon,$eday,$eyea))
{
if ($datediff >= 0)
{

echo “Range is Valid”;
}
else
{

$checkdate = 0;
echo “Range is Invalid”;
$err_array[] = “Incorrect Date Range”;

}
}

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 09.2008 — Can your form be modified to supply the date in a Y2K-compliant format: "yyyy-mm-dd hh:ii:ss"? strtotime() will also recognize "mm/dd/yyyy hh:ii:ss" with slashes, though this may be locale dependent, whereas the Y2K format will always work.
Copy linkTweet thisAlerts:
@rootAug 09.2008 — Convert to milliseconds.

Then compare future date with past date and if past date is < future date then you should be OK.
×

Success!

Help @psdeveloper spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...