Jump to content

date() if statements


plznty

Recommended Posts

How could I make it so that if the $date variable is past than $memberdate then something shows else something else does.

 

<?php
$date = date('Y-m-d H:i:s', time()-3600);
$memberdate = '2011-01-29 01:03:28';
?>

Thanks in advance, I realised I could convert it into a unix timestamp but there must be a better way. Ty.

Link to comment
Share on other sites

Didn't think it would be that easy.

It only works when you satisfy some conditions:

1. All the date components are in descending order. Year, month, day, hour, minute, and second. In that order. Parts can be omitted (in both strings) but not rearranged.

2. The non-numeric characters (ie, separators, like /s and -s and spaces) must be identical in both strings. That means no month names.

3. Each pair of numbers must always be the same length as each other. Like DD/DD and YYYY/YYYY. The easiest way to do that is to zero-pad numbers to a fixed number of digits.

 

So these won't work:

2010-Jan-31 / 2010-Feb-01 - months must be numbers
01-31-2010 / 02-01-2010  - not in descending order
  2010-1-31 / 2010-2-1    - numbers are not the same lengths
2010-01-31 / 2010/02/01  - different separators

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.