Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Need Help w/Date Functions

I need to know why this won't work.
CodeDownload  

$bull = showdate("shortdate", time());
$shit = substr($bull,0,5);
$result = dbquery("SELECT * FROM ".DB_USERS." WHERE DATE_FORMAT(user_birthdate, '%m-%d') = '".$shit."'");


*I realize that I'm comparing a string to a value but don't know how to fix it*

Here is my problem. When pulling user birthdates from the users table I cannot use date("m") and date("d") in the query because it gets those values from the server time and date. I need to get data from the table based on local time and date. Server parameters don't account for the '-6' timezone difference I have set for Central Time but the time format settings (i.e. shortdate), does account for timezone settings. I hope this makes sense.
Try,
CodeDownload  
$result = dbquery("SELECT * FROM ".DB_USERS." WHERE DATE_FORMAT(user_birthdate, '%m-%d') = DATE_FORMAT(NOW(),'%m-%d'");

Quote

Try,
CodeDownload  
$result = dbquery("SELECT * FROM ".DB_USERS." WHERE DATE_FORMAT(user_birthdate, '%m-%d') = DATE_FORMAT(NOW(),'%m-%d'");


I have tried this before. Doesn't work; I tried it just now at 11:40pm and it should have showed my birthday (which I temporarily set for 02/21).
The construct DATE_FORMAT(NOW(),'%m-%d'") is getting it from the server that's why I need to use ("shortdate") which is timezone adjusted.
OK. I finally made it work right. This is the final code that works like it should.
CodeDownload  
$inc1 = showdate("shortdate", time());
$inc2 = substr("$inc1", 0,5);
$result = dbquery("SELECT * FROM ".DB_USERS." WHERE DATE_FORMAT(user_birthdate, '%m/%d') = '$inc2'");



First I executed lines 1 & 2 then did an echo of $inc2 with an exit. I saw that it was generating the substr date as 02/21. I then knew I had to use a slash in the DATE_FORMAT instead of a dash.
Thread Information
Author
Replies
4 posts
Views
141 times
Last Post
Last updated on 1 month ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: Falk, Grimloch