Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-28-2002, 08:57 AM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 12-28-2002, 01:31 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are these vB timestamps or your own table (you mentioned YYYY-MM-DD and vB doesn't store them like that IIRC)?
Reply With Quote
  #3  
Old 12-28-2002, 09:46 PM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by filburt1
Are these vB timestamps or your own table (you mentioned YYYY-MM-DD and vB doesn't store them like that IIRC)?
They are vB's. I think calendar_events.eventdate is the only date field in vB that uses that format instead of the unix timestamp. It's annoying.

I still haven't been able to figure this out.
Reply With Quote
  #4  
Old 12-28-2002, 10:28 PM
futureal futureal is offline
 
Join Date: Feb 2002
Location: Del Mar, CA, USA
Posts: 556
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$today date("Y-m-d",time()); 
And from there, you can just do a normal WHERE clause, such as "WHERE calendardate > $today" or whatever you need.
Reply With Quote
  #5  
Old 12-28-2002, 11:00 PM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by futureal
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:
$today date("Y-m-d",time()); 
And from there, you can just do a normal WHERE clause, such as "WHERE calendardate > $today" or whatever you need.
I tried that. You can't compare strings like that.

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.
Reply With Quote
  #6  
Old 12-29-2002, 04:33 AM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #7  
Old 12-29-2002, 10:38 PM
futureal futureal is offline
 
Join Date: Feb 2002
Location: Del Mar, CA, USA
Posts: 556
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Jakeman

I tried that. You can't compare strings like that.

2002-12-15 >= 2002-12-18 doesn't work.
This should work in MySQL... or at least, it has worked in scripts I have written in the past. If a MySQL field is of the DATE type, the software knows how to compare one date to another.

However, there is another, slightly cleaner option, now that I think about it. Try this:

PHP Code:
SELECT whatever FROM table WHERE UNIX_TIMESTAMP() >= UNIX_TIMESTAMP(date_field); 
Give that a shot and let me know if it works.

Note that the UNIX_TIMESTAMP() function returns the current timestamp when called with no argument.
Reply With Quote
  #8  
Old 12-29-2002, 11:00 PM
Sebastian's Avatar
Sebastian Sebastian is offline
 
Join Date: Oct 2002
Location: America
Posts: 488
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how about something like:

Code:
$today = date("Y-m-d",time());
$month = $today['mon'];
$day = $today['mday'];
$year = $today['year'];
$date = "$year-$month-$day";
fetching like:

[sql]
WHERE (time LIKE '%$date%')
[/sql]
Reply With Quote
  #9  
Old 12-29-2002, 11:58 PM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by futureal
PHP Code:
SELECT whatever FROM table WHERE UNIX_TIMESTAMP() >= UNIX_TIMESTAMP(date_field); 
That appears to be working correctly. Except that it isn't returning events that are equal to the current date, only events that are greater than...

I thought it might be a time offset issue so I tried using:

PHP Code:
$date vbdate("Y-m-d",$ourtimenow);

...

WHERE UNIX_TIMESTAMP($date) >= ... 
That didn't work though... it returned all events, like the WHERE clause was always true.

Any ideas?
Reply With Quote
  #10  
Old 12-30-2002, 01:25 AM
futureal futureal is offline
 
Join Date: Feb 2002
Location: Del Mar, CA, USA
Posts: 556
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Jakeman
That appears to be working correctly. Except that it isn't returning events that are equal to the current date, only events that are greater than...

I thought it might be a time offset issue so I tried using:
Yea, in hindsight I can see where this check would fail.

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:
SELECT whatever FROM table WHERE (UNIX_TIMESTAMP(CONCAT(CURRENT_DATE" 00:00:00"))+86400) >= UNIX_TIMESTAMP(date_field); 
Basically, we're taking today's date (CURRENT_DATE) at midnight and advancing it one full day (86400 seconds) so that we have the timestamp for tomorrow at midnight. Then, any dates that occur up to tomorrow at midnight should be displayed.

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:21 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07927 seconds
  • Memory Usage 2,264KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (6)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete