[advanced search]
Results from the most recent live auction are here.
21 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 01-16-2007, 10:24 AM   · #1
JBebbington
NamePros Regular
 
Trader Rating: (9)
Join Date: Sep 2006
Posts: 626
NP$: 0.00 (Donate)
JBebbington will become famous soon enoughJBebbington will become famous soon enough
Comparing MySQL data to Current Date

Hey All,

I have a database which stores the Date in 3 different fields. send_D for the day, in the format 01, send_M for the month, in the format 01, 02, 03 etc. again, and send_Y for the year, in the form 1992, 1995, 2007 etc.

What I want to know is how would I compare those 3 values to the current date, like how to do "if sql_date = CurrentDate, yada yada yada" in PHP.

Thanks,
Josh.


Please register or log-in into NamePros to hide ads
__________________
The Internets Premier Marketing Community

Coming Soon to a Computer near you... HotHostingDeals.com
JBebbington is offline   Reply With Quote
Old 01-16-2007, 10:43 AM   · #2
Matthew.
Stud Sausage
 
Location: England
Trader Rating: (25)
Join Date: Dec 2006
Posts: 1,545
NP$: 32.41 (Donate)
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
Adoption Breast Cancer Breast Cancer Cancer Survivorship
There are a couple of ways to do this, the first is a little rough by using the date function:

PHP Code:
$str = "{$row['send_D']} {$row['send_M']} {$row['send_Y']}";

if(
date('d m Y') == $str)
{
    
// it is todays date.
}


A little more complicated but more useful method is to create a timestamp using strtotime.

Unfortunately strtotime will not accept the month in numeric terms so we will have to put it into text first

Example:
PHP Code:
$months = array("January","February","March","April","May","June",
                
"July","August","September","October","November", "December");
                
$newmonth = $months[$row['send_M']];

$timestamp = strtotime($row['send_D'] . $newmonth . $row['send_Y']);

if(
date('d m Y') == date('d m y', $timestamp) )
{
    
// Itis todays date.
}


The good thing about that is you now have the timestamp for later use.

Personally i would recommend ditching your current database structure and using 1 field to store a timestamp or at he least NOW(). (The first being preferable).

Things to read:

http://uk2.php.net/strtotime
http://uk2.php.net/time
http://uk2.php.net/date
http://www.google.com/search?hl=en&...amp&btnG=Search
http://dev.mysql.com/doc/refman/5.0...-functions.html
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline   Reply With Quote
Old 01-16-2007, 12:37 PM   · #3
sdsinc
Law and disorder
 
sdsinc's Avatar
 
Name: Kate
Location: Expat
Trader Rating: (57)
Join Date: Aug 2005
Posts: 5,481
NP$: 1585.11 (Donate)
sdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond repute
Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV


IMO it would be better to store dates in a DATE field.
In the meantime this should do the trick:
Quote:
SELECT *
FROM your_table
where TO_DAYS(curdate() )=TO_DAYS( concat(send_Y,'-',send_M,'-',send_D) )

sdsinc is offline   Reply With Quote
Old 01-16-2007, 12:39 PM   · #4
Matthew.
Stud Sausage
 
Location: England
Trader Rating: (25)
Join Date: Dec 2006
Posts: 1,545
NP$: 32.41 (Donate)
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
Adoption Breast Cancer Breast Cancer Cancer Survivorship
Originally Posted by sdsinc


IMO it would be better to store dates in a DATE field.
In the meantime this should do the trick:



And now we see the full reason why i should go off and learn more SQL syntax

My way is messy compared to this. Then again, still stands for:
Quote:
like how to do "if sql_date = CurrentDate, yada yada yada" in PHP.

__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Proof is in the Parking Hunting Moon RealTechNetwork
Advertise your business at NamePros
All times are GMT -7. The time now is 10:59 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0