Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Looking between dates in my db.

Posted on 2011-02-17
5
Medium Priority
?
208 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

609 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