473,414 Members | 2,019 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,414 software developers and data experts.

DaysInYear...

what is the easiest way of establishing this given a Year?

(short of DateTime.parsing a made up string representing 1/1 to 31/12 blah
blah blah)

Thanks
Giri


Nov 15 '05 #1
6 2928

"Giri" <gt******@prologis.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
what is the easiest way of establishing this given a Year?

(short of DateTime.parsing a made up string representing 1/1 to 31/12 blah
blah blah)

Thanks
Giri


DateTime has a static DayInMonth method that accepts a year and a month.
You could loop through all 12 months for a given year, or just check the
number of days in februari to select either 365 or 366 days.

Hans Kesting
Nov 15 '05 #2
Hans and Giri,

That seems much, much longer than this:

public static int DaysInYear(DateTime value)
{
// Get the year. Construct dates for New Year's Day, and subtract.
int pintYear = value.Year;

// Now construct dates and subtract from each other to get the return
value.
int pintRetVal = (new DateTime(pintYear + 1, 1, 1) - new
DateTime(pintYear, 1, 1)).Days;
// That's all folks.
return pintRetVal;
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"Giri" <gt******@prologis.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
what is the easiest way of establishing this given a Year?

(short of DateTime.parsing a made up string representing 1/1 to 31/12 blah blah blah)

Thanks
Giri


DateTime has a static DayInMonth method that accepts a year and a month.
You could loop through all 12 months for a given year, or just check the
number of days in februari to select either 365 or 366 days.

Hans Kesting

Nov 15 '05 #3
Thanks,

DateTime also has a static IsLeapYear() which would seem to be the easiest..
"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"Giri" <gt******@prologis.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
what is the easiest way of establishing this given a Year?

(short of DateTime.parsing a made up string representing 1/1 to 31/12 blah blah blah)

Thanks
Giri


DateTime has a static DayInMonth method that accepts a year and a month.
You could loop through all 12 months for a given year, or just check the
number of days in februari to select either 365 or 366 days.

Hans Kesting

Nov 15 '05 #4

private int DaysInYear(int year)
{
return System.DateTime.IsLeapYear(year) ? 366 : 365;
}
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
For a laugh, try web browsing with Opera's User Mode with Nostalgia enabled
Nov 15 '05 #5
Giri wrote:
what is the easiest way of establishing this given a Year?

(short of DateTime.parsing a made up string representing 1/1 to 31/12 blah
blah blah)

Thanks
Giri


This will take into account leap years, calendars of other cultures, etc.:

using System.Globalization;

// ...

int days = CultureInfo.CurrentCulture.Calendar.GetDaysInYear( year);

Depending on your needs, you might want to use InvariantCulture instead
of CurrentCulture.

--
mikeb
Nov 15 '05 #6
If you want to be accurate, you must get the correct instance of a
Calander-derrived class (from System.Globalization) for the region your
program is executing in. Once you have the correct calander class for the
region, you can query its GetDaysInYear method.

-Rob Teixeira [MVP]

"Giri" <gt******@prologis.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
what is the easiest way of establishing this given a Year?

(short of DateTime.parsing a made up string representing 1/1 to 31/12 blah
blah blah)

Thanks
Giri

Nov 15 '05 #7

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

Similar topics

11
by: Lyle Fairfield | last post by:
The stored procedure script below is an example of how looping, case statements and output parameters can be used in MS-SQL stored procedures to accomplish things for which we may have had to use...
3
by: perryche | last post by:
ie. 365 or 366 days? Perry
1
by: h_ghanaty | last post by:
how i can convert gregorian date to jalaly(Iran date) with vb.net
12
by: Woody Splawn | last post by:
I am trying to determine the age of a person based on two dates, the Date of Birth and Today(). I have a function that does this but it is kludgey and is giving me an age that is pretty close...
13
by: Filips Benoit | last post by:
Dear All, How can I show the resultrecords of a SP. I can be done by doubleclick the SPname? But how to do it by code. I want the following interface In my form the user 1 selects a SP...
8
by: Nor farhana yaakub | last post by:
how r u..hope that u r fine..thanks again 4 ur and everybody's help..it really help...(*_*). By da way,again i have another question.hope u dun mind to teach me coz i need a guide to success and i...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
9
by: ahilar12 | last post by:
1. <head> 2. <script type="text/javascript"> 3. </script> 4. </head> 5. <body> 6. <form> 7. <select name="team" id="mylist" > 8. <option></option> 9....
7
by: peter1234 | last post by:
In the example below I have chosen to define the input variable in a text box called Text_year. The function is run from a for with a Toggle Button. The text box in the same form. My purpose in to...
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: 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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.