Thread: PHP ?
View Single Post
  #3  
Old 10-07-2011, 03:40 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 655,299
Hall of Famer is on a distinguished road
Default

Well a couple of comments to make:
1. You have defined your dates as strings, you cannot compare if a string is greater or smaller than another string, they only work for numbers(integers or floating numbers).
2. In order to compare dates, you will need to convert them into their corresponding timestamp forms. A timestamp defines how many seconds have elapsed since Jan, 1, 1970, its an integer type number.
3. To convert the current date into its corresponding timestamp form, use the function time(). To convert an arbitrary date to timestamp, the function mktime() must be called.

The following sample script is an example of how to compare dates:
PHP Code:
// First get the current date's timestamp using function time()
$badge time();
// Then convert the target dates to their corresponding timestamp form for comparison
$target mktime(0,0,0,9,11,2011);
if(
$badge >= $target){
// codes to execute if the date is after target date, such as Sep,12,2011
}
else{
// codes to execute if the date is before target date, such as Sep,12,2011

__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote