Date is stored in the database in the format YYYY-MM-DD ref. There can't be any slashes if your date is stored in that format. In the example you gave
PHP Code:
SELECT date_format(joined_date,'%d-%m-%Y') as date,joined_date FROM customer where code = '3016'
date_joined is pulled twice and nothing more. If your date is stored in TEXT format like your code implies then you want to use STR_TO_DATE instead and place it to the right of the WHERE.
PHP Code:
<?php
include 'dbconnect.php';
$today='2013-08-23';
$query = "SELECT ID, date_joined FROM test WHERE STR_TO_DATE(date_joined,'%d/%m/%Y') <='$today';";
$test = mysql_query($query);
$test1 = mysql_fetch_array($test,MYSQL_ASSOC);
$test3 = $test1['date_joined'];
echo "$test3<br><br>";
print_r($test1);
?>
STR_TO_DATE() converts the date_joined column and reads it in the DATE format or at least attempts to. Since your date_joined column uses slashes and is listed in the reverse format of DATE you need to tell STR_TO_DATE() to read it that way: STR_TO_DATE(date_joined,'%d/%m/%Y')
Here's a hypothetical example to further demonstrate the usage of STR_TO_DATE(). If you stored it in TEXT format as 'date 08X23X2012' you would use STR_TO_DATE(date_joined,'date %mX%dX%Y') to read it.
Your $fromdate and $todate should also be formatted into YYYY-MM-DD format. Your database column date_joined should be formatted into the date format if it isn't already. Be careful to back up your database first because you will probably need to re-enter the dates into your database. This may seem like a bit of a chore if you have many rows of data, but this can be simplified by writing a php script to do this for you.
AS is also known as an alias. Basically you recognize a column name by another column name.
Bookmarks