Locating the first day of the month in SQL
I needed to select records for this month so far from the database, which required getting the first day of the current month.
After a while, I worked out the following code. To get the prior 12 months, add "- 12 months" after the "+ 1 day" part.
select * from file
where indate >=
date(curdate() - day(curdate()) days + 1 day)
MORE INFORMATION ON THIS TOPIC
The Best Web Links: tips, tutorials and more.
Visit the ITKnowledge Exchange and get answers to your developing questions fast.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.
This was first published in April 2005
Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.