The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
selecting calendar events
I am trying to select calendar events whose eventdates are equal to or greater than the current day (events that haven't already passed). I am having trouble with the WHERE part of the query.
The event dates are stored in YYYY-MM-DD format in the database and I can't figure a way to compare a date in that format in the WHERE line... nor have I been successful in converting the selected eventdate to a UNIX_TIMESTAMP for comparison in the WHERE line (is that even possible?). Help. Thanks. |
#2
|
|||
|
|||
Are these vB timestamps or your own table (you mentioned YYYY-MM-DD and vB doesn't store them like that IIRC)?
|
#3
|
||||
|
||||
Quote:
I still haven't been able to figure this out. |
#4
|
|||
|
|||
You should be able to compare it to a string containing today's date. Use something like this to get today's date:
PHP Code:
|
#5
|
||||
|
||||
Quote:
2002-12-15 >= 2002-12-18 doesn't work. I think I need to compare them in timestamp format but I can't figure out a way to do that. This doesn't work: SELECT eventdate FROM calendar_events WHERE eventdate >= $today I think I need to somehow convert the selected eventdate to timestamp format, but I haven't been able to figure out how to convert the selection in a WHERE clause... I'm beginning to think it's not possible. |
#6
|
||||
|
||||
I was thinking... is there a wildcard for comparing strings in a WHERE clause?
For example, something like: WHERE eventdate = 2002-12-** In this example, the query would return all events in December. Is there any tool like this? |
#7
|
|||
|
|||
Quote:
However, there is another, slightly cleaner option, now that I think about it. Try this: PHP Code:
Note that the UNIX_TIMESTAMP() function returns the current timestamp when called with no argument. |
#8
|
||||
|
||||
how about something like:
Code:
$today = date("Y-m-d",time()); $month = $today['mon']; $day = $today['mday']; $year = $today['year']; $date = "$year-$month-$day"; [sql] WHERE (time LIKE '%$date%') [/sql] |
#9
|
||||
|
||||
Quote:
I thought it might be a time offset issue so I tried using: PHP Code:
Any ideas? |
#10
|
|||
|
|||
Quote:
Suppose is it 12:02 AM on January 1st. An event taking place at 12:10 AM on January 1st would still have a timestamp greater than the current time, while an event taking place at 12:01 AM would not (and would show up). So, here's our solution: PHP Code:
Give that a shot. Oh, and if that does work, you can reward me by taking a look at this thread and see if you can track down one of the moderating corps who might be able to fix my hack thread for me so I can post in it again. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|