473,395 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

last day of previous month

How can i calculate the last day of the previous month?

Help me,please
Jul 20 '05 #1
3 9697
"Killer" <ro*********@tiscali.it> wrote in message news:Sf*******************@twister2.libero.it...
How can i calculate the last day of the previous month?

Help me,please


The last date of previous month:

SELECT CURRENT_TIMESTAMP - DAY(CURRENT_TIMESTAMP)

If you need the date normalized (time of 12:00AM), then:

SELECT CAST(CONVERT(CHAR(8),
CURRENT_TIMESTAMP - DAY(CURRENT_TIMESTAMP),
112) AS DATETIME)

--
JAG
Jul 20 '05 #2
"Killer" <ro*********@tiscali.it> wrote in message news:<Sf*******************@twister2.libero.it>...
How can i calculate the last day of the previous month?

Help me,please


One way:

declare @dt datetime
set @dt = getdate()
select dateadd(dd, -datepart(dd, @dt), @dt)
select convert(char(8), dateadd(dd, -datepart(dd, @dt), @dt), 112)

Simon
Jul 20 '05 #3
Simple date arithmatic. Take first of current month (ie. 5/1/2004)
and subtract 1 day.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ray via SQLMonster.com | last post by:
Hi there, See if you can help me with the following: I need to write an SQL code that will return me: The 1st day & the Last day of the Previous Month in the following format...
13
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not...
7
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date....
9
by: brymcguire | last post by:
Hi, I have a requirement to design a query that identifies items sold between two dates. There is a 'SoldDate' datetime field used to register what date the item was sold. The query needs...
6
by: creative1 | last post by:
hello I am using following code to access first and last date of current month StartingDate_msk.Text = Format$(Date, "dd/mm/yyyy") EndingDate_msk.Text = Format$(MonthLastDay(Date),...
10
by: ashore | last post by:
Guys, the line below just returned "Dec 07" as the date for one month back from today. Hardly life-threatening, but any thoughts? <?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),...
6
by: Supermansteel | last post by:
I have a Query: Date Name Production Which then goes to a Report to reflect that individuals numbers for that month. I have been trying to figure out how to add a field to my report or add it...
1
by: guyborn | last post by:
I have been trying to get data from the database from the of the previous month to the second last week of the current month.I only managed to get data from the previous month to today's date. ...
0
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.