Forum Moderators: coopster

Message Too Old, No Replies

Date selection

Date selection

         

PumpkinHead

10:07 am on May 17, 2004 (gmt 0)

10+ Year Member



Hi,

I have some records in my table that I need to extract if they are equal or greated than the current date. The date fields are in format YYYY-MM-DD. Could someone please provide some details on how to do this in php, I think I have a rough idea.

set date variable to current date
select all records from database where database date is >= current date

Thanks

ukgimp

10:13 am on May 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In your SQL

WHERE DateField >=NOW()

Cheers

venelin13

10:19 am on May 17, 2004 (gmt 0)

10+ Year Member



//we need the date in YYYY-MM-DD format
$current_date = date("Y")."-".date("m")."-".date("d");

$query = "select * from table_name where database_date >= '$current_date' ";

BTW, I always use int(10) to store the dates and I store the date value in UNIX timestamp returned by the PHP time() function. Im my case, the code above will looks like:

//we need the date in YYYY-MM-DD format
$current_date = mktime(0,0,0,date("m"),date("d"),date("Y");

$query = "select * from table_name where database_date >= '$current_date' ";

I think the MySQL server works faster if only some mumbers must be checked, instead of checking valid dates.

PumpkinHead

11:56 am on May 17, 2004 (gmt 0)

10+ Year Member



Great thanks :)

PumpkinHead

9:38 pm on May 19, 2004 (gmt 0)

10+ Year Member



Another problem now!

I am trying to convert the date coming from the database ($date) to a user friendly format (E.g "19th May, 2004").

I am using the following code :

<?

$new_date = mktime(0,0,0,$date("m"),$date("d"),$date("Y");
Print "$new_date";

?>

Can someone point me in the right direction please :)

coopster

9:41 pm on May 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How about strftime() [php.net]?

incywincy

10:17 pm on May 19, 2004 (gmt 0)

10+ Year Member



or maybe use the sql function date_format('$date','%W %M %D %Y');