C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Time is of the essence


Posted Date: 27 Jun 2009    Resource Type: Articles    Category: .NET Framework
Author: Ovidiu TudoracheMember Level: Bronze    
Rating: 1 out of 5Points: 25



While I was working at different projects I encountered frustrating problems related to date and time programming. So I wrote a few classes that helped me tackle this problem.

Helper static class:

* public static DayOfWeek GetLastDayOfWeek(CultureInfo culture)
* public static DateTime GetFirstDateOfWeek(DateTime dateTime, CultureInfo culture)
* public static DateTime GetLastDateOfWeek(DateTime dateTime, CultureInfo culture)
* public static DateTime GetLastDateOfMonth(int year, int month)
* public static DateTime GetLastDateOfYear(int year)
* public static int GetWeeksInYear(int year, CultureInfo culture)
* public static int GetRemainingDaysInWeek(DateTime dateTime, CultureInfo culture)
* public static int GetWeekNumber(DateTime dateTime, CultureInfo culture)
* public static bool AreTimePeriodsIntersecting(TimePeriod tp1, TimePeriod tp2)
* public static bool IsDateInPeriod(DateTime dateTime, TimePeriod timePeriod)

The TimeDifference class receives a start date and an end date and returns the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds and Miliseconds between them in two modes.

Lets take for example two dates: 06/26/2009 and 05/02/2013.

1st difference mode (time-units independence): 4 years, or (more accurately) 47 months or (more accurately), or (more accurately) 200 weeks, or (more accurately) 1406 days

2nd difference mode (time-units dependence): 3 years and 10 months and 6 days

Download code from here. (Changed extension to .zip then unzip.)

Hope it will be of great help to someone and please report any errors or sugestions.

NB: TimeZone and Daylight Savings Time are not taken into account.

Attachments







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
TimePeriod  .  TimeDifference  .  DateTime  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Ways to trigger windows form Control's event
Previous Resource: SQL Server Interview Questions
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use