dates

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

dates

Post by irealms »

at the moment i am selecting by day,month and year using drop down lists, the query is

Code: Select all

<?php


$adate = ''.$_POST['yearstart'].'-'.$_POST['monthstart'].'-'.$_POST['daystart'].'';
$aorders = "SELECT orderno,username,DATE_FORMAT(dateadded, '%d-%m-%Y') AS dateadded,status FROM orders WHERE dateadded='$adate' AND archive='1' ORDER BY dateadded DESC";
		
$aordersq = mysql_query($aorders, $db_conn) or die("Query orders failed".mysql_error());
?>
how do i get it to search by month and year only? I have tried a few things and can't get it to work.
?>
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post by aquila125 »

User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

thanks

Post by irealms »

Thanks aquila it that link was great, got it working now with :

Code: Select all

<?php
$mdate = $_POST['monthstart'];
$ydate = $_POST['yearstart'];
$aorders = "SELECT orderno,username,DATE_FORMAT(dateadded, '%d-%m-%Y') AS dateadded,status FROM orders WHERE MONTH(dateadded)='$mdate' AND YEAR(dateadded)='$ydate' AND archive='1' ORDER BY dateadded DESC";

?>
Post Reply