Help With Dates
Posted: Fri Feb 24, 2006 1:44 pm
The script below is my current script for comparing two dates (also shows what I am doing after the compare). I want to rewrite this script. I am wondering if storing the dates in any other format other than ("m-d-Y") would make this process any easier? I was also wondering if changing the field type to date would make it easier? Right now the field type is text. I thought maybe using the TIMESTAMP or DATE field type would be better?
Suggestions welcome!!!!
$diff - gives me the numerical value of the difference in days.
$date1 - just the numerical day of today.
$date2 - just the numerical value of the stored ECD.
PROBLEM: If the dates go like this:
$date1 is Januarary 1
$date2 is February 22
this program doesent work cause its simply subtracting two numbers, its not going by months, or how many days are in the month for that matter.
Here is the snippet out of my program:
Suggestions welcome!!!!
$diff - gives me the numerical value of the difference in days.
$date1 - just the numerical day of today.
$date2 - just the numerical value of the stored ECD.
PROBLEM: If the dates go like this:
$date1 is Januarary 1
$date2 is February 22
this program doesent work cause its simply subtracting two numbers, its not going by months, or how many days are in the month for that matter.
Here is the snippet out of my program:
Code: Select all
<?php
$date1 = strftime("%d");
list($month, $day) = explode("-", $row["ecd"]);
$date2 = $day;
if($date1 > $date2) {
$diff = $date1 - $date2;
} elseif ($date2 > $date1) {
$diff = $date2 - $date1;
} else {
$diff = "0";
}
if($diff >= "7" || $diff <= "0" || $row["note"] == "false") {
if($row["assigned"] == "false") {
$currenttime = time();
$futurdate = strtotime("+10 days", $currenttime);
echo date("m-d", $futurdate);
} elseif($row["assigned"] == "true" && $row["sent_to_reviewer"] == "false") {
$currenttime = time();
$futurdate = strtotime("+7 days", $currenttime);
echo date("m-d", $futurdate);
} elseif($row["sent_to_reviewer"] == "true") {
$currenttime = time();
$futurdate = strtotime("+2 days", $currenttime);
echo date("m-d", $futurdate);
}
} else {
list($month, $day) = explode("-", $row["ecd"]);
$new_date = $month . "-" . $day;
echo $new_date;
}
?>