Jump to content

[SOLVED] Selecting data between two dates


Recommended Posts

hey there guys,

I want your help. I want to select data between two date (suppose 12-3-2009 to 4-2-2010).

I have converted the strings to date variables.

table's variable is $tbl, starting date's $sdate and ending date is $edate.

Please reply me with some query to solve this jigsaw out.

 

Link to comment
https://forums.phpfreaks.com/topic/180906-solved-selecting-data-between-two-dates/
Share on other sites

its varchar

(`adate` varchar(25) NOT NULL default '', )

 

but i was inserting date in it using

$adate=date("d/m/y h:i:s");

 

should i change composition on table? also what query would work after changing the data type of  adate column

thanks for your time.

And since you can only do greater-than/less-than date comparisons when the field making up the date are ordered left-right, MDS (most significant digit - year) to LDS (least sugnficant digit - day), the only way you will accomplish what you are trying to do will be to get your dates into a format like YYYY-MM-DD and using a DATE data type is the most efficient way of doing that.

how would i format these three variable into a sql recognized date format

$a_date = "$yr-$mon-$dy";

 

the main question remains...

$query = "SELECT * FROM your_table WHERE your_date_column BETWEEN '$sdate' AND '$edate'";

 

BETWEEN is inclusive of the end points. If you want to exclude one of both end point(s), you would need to use greater-than/less-than comparison operators.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.