The SQL query is shown below
SELECT DATEADD(month, DATEDIFF(month, -1, getdate()) - 2, 0) as FirstDayWithTime,
DATEADD(ss, -1, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) as LastDayWithTime
We can find out the first and last day with time of the previous month by simple step.
The SQL query is shown below
SELECT DATEADD(month, DATEDIFF(month, -1, getdate()) - 2, 0) as FirstDayWithTime,
DATEADD(ss, -1, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) as LastDayWithTime
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegisterMembers onlyeBook · SQLSupabase in Practice: Build and Ship Production Apps on Postgres, from First Table to LaunchDownload nowWrite a blog post and earn +250 SHARP when it is approved.
Write a blog
Join the conversation! Your thoughts help the community grow.