473,471 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

to generate all the dates for a given month and year..

30 New Member
hi frenz,

I want to display all the dates and day of the given year and month.
For ex; if i choose 2007 and select the month January, i want to generate all the dates for this selection
1/1/2007
2/1/2007
....
...
..
31/1/2007,
and the day name (monday,tuesday...) for all the generated dates. Also, need to check for the leapyear, and generate the dates accordingly. Pls provide some kind-a help. its urgent. I'm able to generate the dates, but need to display the dayname and chk for leap year.

Cheers,
jai
Mar 28 '07 #1
2 3307
iburyak
1,017 Recognized Expert Top Contributor
Try this:

[PHP]Declare @year int, @month int, @StartDate datetime, @EndDate datetime
Declare @Date datetime

SET @year = 2008
SET @month = 2
SET @StartDate = cast(cast(@month as varchar(10)) + '-1-' + cast(@year as varchar(10)) as datetime)
SET @EndDate = dateadd(m,1,@StartDate)

DECLARE @temp TABLE (Date_Time varchar(50))

SET @Date = @StartDate

While @Date < @EndDate
BEGIN

INSERT INTO @temp
SELECT DATENAME (dw, @Date) + ', ' + convert(varchar(30), @Date, 110)

SELECT @Date = dateadd(d,1, @Date)
END

SELECT * from @temp[/PHP]


Don't worry about leap year it will be handled with internal calendar.

Good Luck.
Mar 28 '07 #2
jai80
30 New Member
Hi iburyak,

Thanks for your help. Sorry for the late reply. i was also working on the code and got the desired output. Once again, thank you.

Cheers,.
jai
Try this:

[PHP]Declare @year int, @month int, @StartDate datetime, @EndDate datetime
Declare @Date datetime

SET @year = 2008
SET @month = 2
SET @StartDate = cast(cast(@month as varchar(10)) + '-1-' + cast(@year as varchar(10)) as datetime)
SET @EndDate = dateadd(m,1,@StartDate)

DECLARE @temp TABLE (Date_Time varchar(50))

SET @Date = @StartDate

While @Date < @EndDate
BEGIN

INSERT INTO @temp
SELECT DATENAME (dw, @Date) + ', ' + convert(varchar(30), @Date, 110)

SELECT @Date = dateadd(d,1, @Date)
END

SELECT * from @temp[/PHP]


Don't worry about leap year it will be handled with internal calendar.

Good Luck.
Apr 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: David Gray | last post by:
Greetings all, Quick newbie type question: I would like to be able to trap non-numerical data entered into a textbox via CTRL+C and/or Shift+Insert. I realise that this data can be...
11
by: Amy G | last post by:
I have seen something about this beofore on this forum, but my google search didn't come up with the answer I am looking for. I have a list of tuples. Each tuple is in the following format: ...
9
by: Thomas W | last post by:
I'm developing a web-application where the user sometimes has to enter dates in plain text, allthough a format may be provided to give clues. On the server side this piece of text has to be parsed...
4
by: F | last post by:
Hi I have posted the question few days back about problem in inserting the dates in SQL server and thankful to them who replied. That was solved and this is a nice solution....
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
52
by: Andy Dingley | last post by:
I'm using this at present: <p title="Publication date" ></p> Works fine on screen, but Fangs/Jaws just reads it as "left bracket twenty-eight slash zero slash two thousand five fifteen colon...
3
by: David | last post by:
I'm new to DB2 and I need to write a query that will allow me to find specific dates instead of me having a date range asked for, I want it to be calculated. I've done this in Access by coding...
4
by: Russell | last post by:
I have an assignment that I have to complete. I have to write a windows app in C#. Here is the spec: 1/ Date Comparison Build a program that will find the number of days between two dates. You...
6
by: Kentor | last post by:
does anyone know of a script that would produce a calendar starting from todays date with checkboxes next to every day of the month so that the user is able to check it in case of an event for that...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.