help with mySQL select where dates >= todays date?

Codes here !

Moderators: macek, egami, gesf

cgchris99
New php-forum User
New php-forum User
Posts: 19
Joined: Sun Apr 13, 2003 7:23 pm

help with mySQL select where dates >= todays date?

Postby cgchris99 » Sun Apr 13, 2003 7:26 pm

I have a DB that has the date entered in three fields.
Month (long form like february)
Day
Year

With these three fields how can I do a select where the some function to combine these three fields is >= todays date?

thanks for any help

php-vikas
New php-forum User
New php-forum User
Posts: 164
Joined: Mon Apr 14, 2003 12:25 am
Location: India
Contact:

Postby php-vikas » Mon Apr 14, 2003 1:19 am

Hi

For doing this, first of all you have to extract the current date's day, month and year into seprare variable's

$date=date("Y-m-d"); // Would retrive the current date.

$date=explode("-",$date); //break the date detail into the array.

$year=$date[0];
$month=$date[1];
$day=$date[2];

Now you can write your query as following.

select * from db where year>$year and month>$month and day>$day

I hope this would work for you.

if you get any problem then please dont hasitate to ask again and again.

Vikas Garg

cgchris99
New php-forum User
New php-forum User
Posts: 19
Joined: Sun Apr 13, 2003 7:23 pm

Postby cgchris99 » Mon Apr 14, 2003 4:21 pm

Thanks for the reply. I have one small problem

In the Select statemen the part where month>$month

month = 'April' and $month=04

How do I fix this?

Thanks so much for you help

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Mon Apr 14, 2003 11:30 pm

i have a date thing like that, i used one field for the date. in mysql you set the field type to date, and you enter your date in the y-m-d format, like 2003-04-14. then you can have...

$today = date( "y-m-d");
SELCT fields FROM table WHERE date>=$today


Then when displaying the date, you can manipulate it display anything that a timestamp can do.

$date = strtotime ($myrow["date"]);
$formatdate = date('d-M',$date);

myrow is the array that was fetched. strtotime converts dates into a timestamp, then the date function formats it. To see all the ways you can format the date, or time view the date function properties on http://www.php.net


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 3 guests