Hi All,
I am querying a date from a database in the format of 01/23/03 or mm/dd/yy.
What I want to do is display a value (Yes) if todays date is >= 10 days past the date that I pull from the db.
the part in bold below is what I don't know how to do. If the db $date entry is 01/10/03, I want it to display "Pending" between the 10th and the 20th and "Yes" every day after 01/20/03.
if ($date + 10 days >= today) {
$entry = "Yes";
} else {
$entry = "Pending";
}
I hope this is explained good enough.
Thanks in advance.Hedgehog,
I'd do something like:
$today = date("Ymd");
$dbdate = explode("/", $date);
$fdate = $dbdate[2] . $dbdate[0] . ($dbdate[1] + 10);
if ($fdate >= $today) {
$entry = "Yes";
} else {
$entry = "Pending";
}I think you will have troubles if you use the date that has / in it. let me write something up in a bit. I have to run out the door so it will be awhile.
in the mean time you can look into strtotime or mktime to do what you want.Thanks Inch, I will try your option later this evening to see if it works.
Scoutt, The important thing here is I have to somehow use the mm/dd/yy format coming from the database because there is already about 400 entries and I don't want to go back and change the date format in the db for every entry.
Thanksthen Inch's code should work. I knew you didn't want to change th date but it will make thing s alot easier to do it with the year first. instead of the monthThanks Inch and Scoutt.
It works fine, I just had to adjust a couple things:
changed the "Y" to "y" for "03"
changed "$fdate >= $today" to "$today >= $fdate"
$today = date("ymd");
$dbdate = explode("/", $date);
$fdate = $dbdate[2] . $dbdate[0] . ($dbdate[1] + 10);
if ($today >= $fdate) {
$entry = "Yes";
} else {
$entry = "Pending";
}
Thanks again.Hey Inch or Scoutt....Help!
This script worked fine until Feb. 1, now it displays all the output "Yes" even if the db entry was 01/30/03.
This is what I am using:
$today = date("ymd");
$dbdate = explode("/", $date);
$fdate = $dbdate[2] . $dbdate[0] . ($dbdate[1] + 10);
if ($today >= $fdate) {
$entry = "Yes";
} else {
$entry = "Pending";
}
Here are the results:
for db entry 01/29/03 - $fdate = 030139
for db entry 01/30/03 - $fdate = 030140
for db entry 01/31/03 - $fdate = 030141
Any ideas?
HedgeHogevery month you will have problems and evey year you will have problems. I told you that using the date like that will hurt yeah
so what we have to do is this. we will change the date to a time format. so give this a try
$today = time();
$dbdate = strtotime($date);
$fdate = ($dbdate + 864000); // 86400 = 1 day in seconds
if ($today >= $fdate) {
$entry = "Yes";
} else {
$entry = "Pending";
}Works Perfect!
Thanks once again Scoutt!
HedgeHog
I am querying a date from a database in the format of 01/23/03 or mm/dd/yy.
What I want to do is display a value (Yes) if todays date is >= 10 days past the date that I pull from the db.
the part in bold below is what I don't know how to do. If the db $date entry is 01/10/03, I want it to display "Pending" between the 10th and the 20th and "Yes" every day after 01/20/03.
if ($date + 10 days >= today) {
$entry = "Yes";
} else {
$entry = "Pending";
}
I hope this is explained good enough.
Thanks in advance.Hedgehog,
I'd do something like:
$today = date("Ymd");
$dbdate = explode("/", $date);
$fdate = $dbdate[2] . $dbdate[0] . ($dbdate[1] + 10);
if ($fdate >= $today) {
$entry = "Yes";
} else {
$entry = "Pending";
}I think you will have troubles if you use the date that has / in it. let me write something up in a bit. I have to run out the door so it will be awhile.
in the mean time you can look into strtotime or mktime to do what you want.Thanks Inch, I will try your option later this evening to see if it works.
Scoutt, The important thing here is I have to somehow use the mm/dd/yy format coming from the database because there is already about 400 entries and I don't want to go back and change the date format in the db for every entry.
Thanksthen Inch's code should work. I knew you didn't want to change th date but it will make thing s alot easier to do it with the year first. instead of the monthThanks Inch and Scoutt.
It works fine, I just had to adjust a couple things:
changed the "Y" to "y" for "03"
changed "$fdate >= $today" to "$today >= $fdate"
$today = date("ymd");
$dbdate = explode("/", $date);
$fdate = $dbdate[2] . $dbdate[0] . ($dbdate[1] + 10);
if ($today >= $fdate) {
$entry = "Yes";
} else {
$entry = "Pending";
}
Thanks again.Hey Inch or Scoutt....Help!
This script worked fine until Feb. 1, now it displays all the output "Yes" even if the db entry was 01/30/03.
This is what I am using:
$today = date("ymd");
$dbdate = explode("/", $date);
$fdate = $dbdate[2] . $dbdate[0] . ($dbdate[1] + 10);
if ($today >= $fdate) {
$entry = "Yes";
} else {
$entry = "Pending";
}
Here are the results:
for db entry 01/29/03 - $fdate = 030139
for db entry 01/30/03 - $fdate = 030140
for db entry 01/31/03 - $fdate = 030141
Any ideas?
HedgeHogevery month you will have problems and evey year you will have problems. I told you that using the date like that will hurt yeah
so what we have to do is this. we will change the date to a time format. so give this a try
$today = time();
$dbdate = strtotime($date);
$fdate = ($dbdate + 864000); // 86400 = 1 day in seconds
if ($today >= $fdate) {
$entry = "Yes";
} else {
$entry = "Pending";
}Works Perfect!
Thanks once again Scoutt!
HedgeHog