Playing with Dates

while developing e-commerce project i got requirement like if any user purchase free trail product our website send one link to him which is limited for 3 days,so after 3 days if user click on that link it will show a message like “Your link has been expire”.

so first thing we need to create future date. below function help to create future date.

$limit_date = mktime(0,0,0,date("m"),date("d")+3,date("Y"));

next thing we need to think is how to compare two dates?

we can not directly use comparison operator for dates, so we need to use bellow function

The strtotime() function parses an English textual date or time into a Unix time stamp.

$cdate = date("Y-m-d");
$d1 = strtotime($cdate);
$d2 = strtotime($limitdate);
if($d1 > $d2)
{
	echo "limit over";
}

Done!!..!!  🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s