473,835 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

last day of previous month

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

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

Help me,please


The last date of previous month:

SELECT CURRENT_TIMESTA MP - DAY(CURRENT_TIM ESTAMP)

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

SELECT CAST(CONVERT(CH AR(8),
CURRENT_TIMESTA MP - DAY(CURRENT_TIM ESTAMP),
112) AS DATETIME)

--
JAG
Jul 20 '05 #2
"Killer" <ro*********@ti scali.it> wrote in message news:<Sf******* ************@tw ister2.libero.i t>...
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
5762
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 (smalldatetime): yyyy-mm-dd hh:mi:ss (24h)
13
3625
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 sure if it can be done, but all help welcomed. E.g. I have December and would like to see the last 2 weeks.. So this doesnt mean the last 15 days. What i mean by this is...
7
6041
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************************************** GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31) End Function If I enter dtDay value of...
9
4656
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 to identify all sales between the last day of the previous month and going back one year.
6
24808
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), "dd/mm/yyyy")can some one help me how I can find fist and last date of previous month? chill farhana
10
3286
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"), date("Y")));?> AS
6
1363
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 to my Query to reflect that same persons Production numbers from the previous month on the Same report. So, that person can not only see how they did that month, but there production % from the previous month as well. Anybody know if this is...
1
2318
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. your help will be highly appreciated Regards Guyborn
0
2367
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 ASP.NET a DataGrid with Updatable rows based on a date retrieved from a data table in SQL Server. Below is the design algorithm. 1. Retrieve the Max(rundate) From MyDataTable 2. If the current month -1 = rundate .month from step 1 then 2a. ...
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10524
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10562
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6968
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3997
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3092
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.