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
https://forums.phpfreaks.com/topic/226012-date-if-statements/
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
https://forums.phpfreaks.com/topic/226012-date-if-statements/#findComment-1166806
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.