Hi,
does anyone have any idea how can we get last date of the month in SQL reportging.
I am using following fomula, but it works only for 31 days of month, not for feb,april,june...(30 days)
=month(today())& "/" & DatePart("d", DateAdd("d", -1, DateAdd("m", 1, DateAdd("d", -DatePart("d", today()) + 1, today())))) & "/" & year(today())
3 4151
Hi
Using T-SQL, try this:- - [size=1]
-
declare @d datetime
-
declare @mth tinyint
-
set @mth = datepart(mm,getdate())+1
-
if @mth=13 set @mth = 1
-
set @d = dateadd(d,-1,convert(datetime,cast(@mth as nvarchar(2)) +'/01/2007',101))
-
HTH
Steve
Hi,
try this ...
declare @year int,@month int
declare @FirstDate datetime, @LastDate datetime
declare @MonthDays int
set @year=2006
set @month=4
set @FirstDate=convert(datetime, convert(varchar,@month)+'/'+'01'+'/'+ convert(varchar,@year) )
set @MonthDays= DAY(DATEADD(d, -DAY(DATEADD(m,1,@FirstDate)),DATEADD(m,1,@FirstDat e)))
set @LastDate=dateadd(d,@MonthDays-1,@FirstDate)
select @LastDate
GudLuck
Cheers,
jai
Hi Folks,
Just thought I'd toss this up here.
declare @ld_date datetime
set @ld_date = '2008-11-01'
select dateadd(day, (-1 * datepart(day, dateadd(month, 1, @ld_date))), dateadd(month, 1, @ld_date))
Cheers
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
by: Jennifer Lee |
last post by:
Hello,
Does anyone happen to have a function, prefereably in pl/pgsql, which
given the month and year will return the last day in that month?
Thanks,
Jennifer
...
|
by: Gol Yass |
last post by:
Dear Newsgroup,
Is there a function in Access XP to take a date or month , and return the
last day in that month?
Ex: the last day in september is 30 or the last day in May is 31 .
Thank...
|
by: Sue |
last post by:
I'm working on a database that keeps track of employees hired by a general
contractor on a project by project basis. These employees are hired to work
on a project and are then laid off either at...
|
by: Sasidhar Parvatham |
last post by:
Hello All,
Is there a way I can get dates for first and last fridays of a month? Any
suggestion would be helpful.
Thanks.
|
by: laredotornado |
last post by:
Hi, Using PHP 4, if I have a date, what is a function I could use to
give me a date that represents the first day of that month? For
example, if my date were "3/19/2006 8:00", I would want my...
|
by: thebjorn |
last post by:
For the purpose of finding someone's age I was looking for a way to
find how the difference in years between two dates, so I could do
something like:
age = (date.today() - born).year
but that...
|
by: ats |
last post by:
Does anybody have any sample code for calculating the date for teh last
Friday in each month.
TIA
--
ats@jbex
When an old lady got hit by a truck
I saw the wicked gleam in your eyes
|
by: code green |
last post by:
On the first of each month I need to create a report from the previous month covering 1-15 and 16-end of month.
I am using the following code which forms part of a mssql query and part of the...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |