473,396 Members | 1,738 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,396 software developers and data experts.

Date Arithmetic

Gil
I run a webserver on Win2k Server and program in vb.net.

I am trying to perform a calculation that results in two
weeks of data given any selected date that starts with
the Sunday of the selected date. In order to accomplish
this I need to perform some date arithmetic.

For instance, if a user enters 11/6/2003 (Thu), then I
want to generate data from 11/2/2003 to 11/15/2003. If I
choose 11/3/2003 (Mon), this too would generate 11/2/2003
to 11/15/2003. But if I choose 11/10/2003, then I would
generate 11/9/2003 to 11/22/2003.

To do this my plan was to convert a Date to Int, perform
arithmetic, then convert back to Date. What I envisioned
was something like this:

If Weekday(SelectedDate) > 1
Then StartDate = CDate(CInt(SelectedDate) - Weekday
(SelectedDate) + 1)
End If

EndDate = CDate(CInt(StartDate) + 13)

This does not seem to work. I have even tried to use
CType to coerce, unsucessfully.

Please help.
TIA,
Gil
Jul 21 '05 #1
1 5166
Gil <an*******@discussions.microsoft.com> wrote:
I run a webserver on Win2k Server and program in vb.net.

I am trying to perform a calculation that results in two
weeks of data given any selected date that starts with
the Sunday of the selected date. In order to accomplish
this I need to perform some date arithmetic.

For instance, if a user enters 11/6/2003 (Thu), then I
want to generate data from 11/2/2003 to 11/15/2003. If I
choose 11/3/2003 (Mon), this too would generate 11/2/2003
to 11/15/2003. But if I choose 11/10/2003, then I would
generate 11/9/2003 to 11/22/2003.

To do this my plan was to convert a Date to Int, perform
arithmetic, then convert back to Date. What I envisioned
was something like this:


I'd suggest using DateTime.DayOfWeek, and then DateTime.AddDays
appropriately depending on the retrieved day of the week.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

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

Similar topics

5
by: gsv2com | last post by:
Maybe I'm tired, but I'm having a small problem with a date function I'm writing. Total noobish I know, but this is just going beyond me for some reason... What I want to happen is send a date...
7
by: Mick White | last post by:
According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation. I am interested in dates from 1500 to 1901, as far as...
26
by: sgershon | last post by:
Hi. I know this is should be a simple question. I know server-side web-programming, and never needed to use client-side scripting... until now :) I have done so far a little number of scripts...
1
by: Penguin | last post by:
For some odd reason, I am trying to do some complex time calculations that I want to let the user define. So I set up a table with EventID EventType EventExpression 1 ...
1
by: Gil | last post by:
I run a webserver on Win2k Server and program in vb.net. I am trying to perform a calculation that results in two weeks of data given any selected date that starts with the Sunday of the...
0
by: Howard Hinnant | last post by:
I'm tossing my date class into the public domain because I'm tired of it sitting around gathering dust. It was first created over a decade ago and has been evolving by bits and pieces since then....
335
by: extrudedaluminiu | last post by:
Hi, Is there any group in the manner of the C++ Boost group that works on the evolution of the C language? Or is there any group that performs an equivalent function? Thanks, -vs
4
by: thomasc1020 | last post by:
This is regarding VB.NET 2003. Variable 'Date' is a string and it contains date information in this format: "DEC/05/2007". Now I am trying to convert the format as "2007-12-05". Is it...
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
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
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,...

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.