|
-
Jan 29th, 2003, 10:48 PM
#1
Thread Starter
Stuck in the 80s
[Resolved] Date Comparison Problems
I'm having a problem comparing dates. I've tried the following two:
Code:
//tried this:
if ($comic['released'] <= date('Y-m-d')) {
$date = "Now!";
} else {
$date = date('F jS, Y', strtotime($comic['release'])) . ".";
}
//and this:
if (date('Y-m-d', strtotime($comic['released'])) <= date('Y-m-d')) {
$date = "Now!";
} else {
$date = date('F jS, Y', strtotime($comic['release'])) . ".";
}
$comic['released'] is a date format in MySQL.
No matter what, it always prints "Now!"
Where am I going wrong?
Last edited by The Hobo; Jan 30th, 2003 at 12:58 PM.
-
Jan 30th, 2003, 10:39 AM
#2
Frenzied Member
-
Jan 30th, 2003, 12:33 PM
#3
Thread Starter
Stuck in the 80s
Originally posted by phpman
make date a variable.
What...?
-
Jan 30th, 2003, 12:45 PM
#4
Frenzied Member
PHP Code:
$newdate = date("Y-m-d");
try to stay away form ' in the variables. I found out the last couple of days that is is totally different then using "
so they are different
$some['variable']
$some["variabel"]
one will be correct as the other one will be empty.
-
Jan 30th, 2003, 12:48 PM
#5
Thread Starter
Stuck in the 80s
Originally posted by phpman
PHP Code:
$newdate = date("Y-m-d");
What difference is that going to make?
Originally posted by phpman
try to stay away form ' in the variables. I found out the last couple of days that is is totally different then using "
so they are different
$some['variable']
$some["variabel"]
one will be correct as the other one will be empty.
I've never had a problem using single quotes before.
-
Jan 30th, 2003, 12:51 PM
#6
Thread Starter
Stuck in the 80s
No luck:
Code:
$today = date('Y-m-d');
$released = date('Y-m-d', strtotime($comic['released']));
if ($released <= $today) {
$date = "Now!";
} else {
$date = date('F jS, Y', strtotime($comic['release'])) . ".";
}
Am I setting up the comparison wrong?
I want to say is $released less than or equal to $today. That's right, isn't it?
-
Jan 30th, 2003, 12:52 PM
#7
Hyperactive Member
maybe it would be easier to compare using a unix timestamp, where its just a straight number.
-
Jan 30th, 2003, 12:53 PM
#8
Thread Starter
Stuck in the 80s
Even when I compare them as timestamps, it doesn't work.
-
Jan 30th, 2003, 12:53 PM
#9
Thread Starter
Stuck in the 80s
Damn, I just found my problem...
Code:
$today = date('Y-m-d');
$released = date('Y-m-d', strtotime($comic['released']));
if ($released <= $today) {
$date = "Now!";
} else {
$date = date('F jS, Y', strtotime($comic['release'])) . ".";
}
-
Jan 30th, 2003, 12:55 PM
#10
Frenzied Member
Originally posted by The Hobo
No luck:
Code:
$today = date('Y-m-d');
$released = date('Y-m-d', strtotime($comic['released']));
if ($released <= $today) {
$date = "Now!";
} else {
$date = date('F jS, Y', strtotime($comic['release'])) . ".";
}
Am I setting up the comparison wrong?
I want to say is $released less than or equal to $today. That's right, isn't it?
yeah that is correct. I have had simialar problems and making the date as a variable makes it simplified and the problem went away.
what is $comic['released'] - the value of it?
-
Jan 30th, 2003, 12:57 PM
#11
Frenzied Member
hehe I hate those with a passion
-
Jan 30th, 2003, 12:57 PM
#12
Thread Starter
Stuck in the 80s
Originally posted by phpman
what is $comic['released'] - the value of it?
It was supposed to be $comic['release'] I make dumbass mistakes like this all the time, and it takes me hours to figure it out.
So this is the code I'm using now:
Code:
if (strtotime($comic["release"]) <= strtotime("now")) {
$date = "Now!";
} else {
$date = date('F jS, Y', strtotime($comic['release'])) . ".";
}
*sighs* Thanks for all your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|