The question is to Produce a list of the latest movies by genres for the current month. How to find the current month from the Date???
Asked
Active
Viewed 1,314 times
-1
-
Which rdbms are you using (you've tagged two different ones here), and did you try googling for an answer? – TZHX Mar 16 '17 at 19:45
-
show text non img ... – ScaisEdge Mar 16 '17 at 19:45
-
Possible duplicate of [What is the best way to truncate a date in SQL Server?](http://stackoverflow.com/questions/2639051/what-is-the-best-way-to-truncate-a-date-in-sql-server) – James Z Mar 16 '17 at 19:46
-
What is the datatype of `ReleaseDate`? – Cato Minor Mar 16 '17 at 19:50
-
The data type for release date is Date – V0711 Mar 16 '17 at 19:55
2 Answers
0
You are looking for DATEPART()
Select
*
From YourTable
Where
datepart(month,ReleaseDate) = datepart(month,getdate())
and datepart(year,ReleaseDate) = datepart(year,getdate())
Order by Genre, ReleaseDate desc

S3S
- 24,809
- 5
- 26
- 45
0
You can try this:
SELECT SUBSTRING(TO_CHAR(now(),'YYYYMMDD'),5,2)
In which:
Format to date and you get only the month

AT82
- 71,416
- 24
- 140
- 167

Ing. Edgar Román
- 11
- 3