?
Solved

Looking between dates in my db.

Posted on 2011-02-17
5
Medium Priority
?
207 Views
Last Modified: 2012-05-11
$firstOfMonth = date("Y-m-d", strtotime('01/'.date('m').'/'.date('Y').'00:00:00'));
$lastOfMonth = date("Y-m-d", strtotime('-1 second',strtotime('+1 month',strtotime('01/'.date('m').'/'.date('Y').'00:00:00'))));
echo $firstOfMonth.'....'.$lastOfMonth;
 $getuserprofile =  mysql_query("SELECT * from race12 WHERE ev_dat between '$firstOfMonth' and '$lastOfMonth'");
 $num_rows = mysql_num_rows( $getuserprofile);

Open in new window



Im getting no results even though there are 2 dates with 2011-02-10

and when i echo
echo $firstOfMonth.'....'.$lastOfMonth;

Open in new window


i get

2011-01-02....2011-02-01 when it should be 2011-01-01....2011-01-lastday
0
Comment
Question by:runnerjp2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:dsmile
ID: 34914675
2011-01-02....2011-02-01 when it should be 2011-01-01....2011-01-lastday

--> do you mean

2011-01-02....2011-02-01 when it should be 2011-02-01....2011-02-lastday
0
 

Author Comment

by:runnerjp2005
ID: 34914686
woops... yes i do lol
0
 
LVL 13

Expert Comment

by:dsmile
ID: 34914721
If that was the case then the part of preparing input date should be like this

$firstOfMonth = date("Y-m-d", strtotime(date('m').'/01/'.date('Y').' 00:00:00'));
$lastOfMonth = date("Y-m-d", strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00'))));

What is type of ev_dat?
You query will only work if its type is DATE
0
 
LVL 13

Accepted Solution

by:
dsmile earned 2000 total points
ID: 34914735
BTW, you don't have to create exact last date.
To fulfill your requirement of select data from first to last date of the month, you can easily (and safely)  use this

$firstOfMonth = date("Y-m-01");
$lastOfMonth = date("Y-m-31");

Cheers
0
 

Author Closing Comment

by:runnerjp2005
ID: 34914757
thats WELL easy to the way i am doing it...thanks :)
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question