Solved

Looking between dates in my db.

Posted on 2011-02-17
5
203 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 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Make login page safer 3 31
Multi line FPDF footer: 3 23
What is define("__APPROOT__", __DIR__); 6 28
How do I fix this error with quotation marks? 4 24
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

735 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