472,378 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

startdate / enddate sum

all,
I have a startdate and enddate, i wish to be able to calculate how
many weeks have been selected. so for example, using the startdate and
enddate, i select 11/02/2008 and 25/02/2008 i need a method to sum how
many weeks that is.
Any suggestions?Where do i start?

Cheers!
Feb 28 '08 #1
4 1857
DateTime start = new DateTime(2008,02,11), end = new
DateTime(2008,02,25);
double weeks = end.Subtract(start).TotalDays / 7;

You might want to use Math.Floor() or Math.Ceiling() to round up or down...

Marc
Feb 28 '08 #2
On 28 Feb, 09:39, "Marc Gravell" <marc.grav...@gmail.comwrote:
* * * * * * DateTime start = new DateTime(2008,02,11), end = new
DateTime(2008,02,25);
* * * * * * double weeks = end.Subtract(start).TotalDays / 7;

You might want to use Math.Floor() or Math.Ceiling() to round up or down....

Marc
thanks for your replies! great help.
Marc, could i do the following..
DateTime start = new DateTime(variable name), end = new
DateTime(variable name);
double weeks = end.Subtract(start).TotalDays / 7;
because those dates are selected at the users command. then using
Math.Floor() to round up?
Feb 28 '08 #3
It depends what [variable name] is...
If it is already a DateTime, then just use in place of [start] and [end]
If they are strings, then you'll need to use DateTime.Parse().

Alternatively, give the user a date-picker, and just use the .Value (which
should be a DateTime).

Marc
Feb 28 '08 #4
Finished code:

// Convert strings to DateTime
DateTime dtStart = Convert.ToDateTime(udt.strStartDate);
DateTime dtEnd = Convert.ToDateTime(udt.strEndDate);

// Subtracts End Date from Start Date
double weeks = dtEnd.Subtract(dtStart).TotalDays / 7;

// Rounds the value to the closest whole number int
double fvWeeks = Math.Floor((weeks + 0.5));

Regards to Jon Skeet & Marc Gravell
Feb 28 '08 #5

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

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...
2
by: Mark | last post by:
What is the code to do the following -- If txtEndDate < txtStartDate txtEndDate = null txtEndDate setfocus End If Also, what event should the code be in? Thanks!
1
by: Ray S via .NET 247 | last post by:
(Type your message here) Can anyone show me how to sort items using ChannelItem.StartDate property. I need to sort items so that the most recent items is at the top. Thanks...
1
by: Jeremy Ames | last post by:
I have a datagrid that updates the table using a stored procedure. The stored procedure is confirmed to complete correctly, yet the sql data adapter is returning an error that my application is...
1
by: ndindi22 | last post by:
Can someone plz help me. I'm working on leave application, have to calculate number of leave days available, starting from Startdate to Enddate of a contract. Where an employee get 1 day leave...
2
by: sd_eds | last post by:
I have a startdate-enddate dropdown in asp that works great on my development machine (XP Pro IIS5) but when I port it over to the web server (Win Server 2003, IIS6), I do not get the desired...
2
by: HoganGroup | last post by:
Hi fellows: I am at a complete lost as to how to construct a query or report to answer this question. Any help is greatly appreciated. The question I need to answer is this: Identify the SchID...
7
hodgeman
by: hodgeman | last post by:
Hello thescripts forums users... I've found a lot of answers to problems I've had in the past from this forum, and this is the first mySQL query issue I haven't been able to find an answer from...
2
by: Mike P | last post by:
How do you take 2 dates (a startdate and an enddate), and then add all the dates between them to an ArrayList? This is as far as I have got so far, I'm not sure what to do next : DateTime...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.