473,779 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determining a DateTime by adding a number of Days to a Date - Help

PK9
I have a loop where I need to calculate a series of dates based on:
1) a start date (DateTime variable)
2) a number of days (integer variable)

I need to take the start date, then add the number of days to it, and come
up with the next date.

eg.
- DateTime variable might equal 01/02/2005
- My integer for "Number of Days" is 10
- I need to take my DateTime variable (01/02/2005) and add the integer 10
(for 10 days) to it. This should produce the result of 01/12/2005 as a
DateTime variable.

Any ideas on how to go about this?
--
PK9
Jul 21 '05 #1
2 1656
Try this.

DateTime origDate = DateTime.Now;
DateTime result = origDate.AddDay s(10);

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"PK9" <PK*@discussion s.microsoft.com > wrote in message
news:A0******** *************** ***********@mic rosoft.com...
I have a loop where I need to calculate a series of dates based on:
1) a start date (DateTime variable)
2) a number of days (integer variable)

I need to take the start date, then add the number of days to it, and come
up with the next date.

eg.
- DateTime variable might equal 01/02/2005
- My integer for "Number of Days" is 10
- I need to take my DateTime variable (01/02/2005) and add the integer 10
(for 10 days) to it. This should produce the result of 01/12/2005 as a
DateTime variable.

Any ideas on how to go about this?
--
PK9

Jul 21 '05 #2
PK9
Perfect. Thank you.

"Dennis Myrén" wrote:
Try this.

DateTime origDate = DateTime.Now;
DateTime result = origDate.AddDay s(10);

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"PK9" <PK*@discussion s.microsoft.com > wrote in message
news:A0******** *************** ***********@mic rosoft.com...
I have a loop where I need to calculate a series of dates based on:
1) a start date (DateTime variable)
2) a number of days (integer variable)

I need to take the start date, then add the number of days to it, and come
up with the next date.

eg.
- DateTime variable might equal 01/02/2005
- My integer for "Number of Days" is 10
- I need to take my DateTime variable (01/02/2005) and add the integer 10
(for 10 days) to it. This should produce the result of 01/12/2005 as a
DateTime variable.

Any ideas on how to go about this?
--
PK9


Jul 21 '05 #3

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

Similar topics

8
1956
by: Joshua Beall | last post by:
Hi All, I am wondering what the best way to determine an age of something/somone is. For instance, let's say I have two dates: 1985-07-19 2003-11-30 Now, I want to determine the interval in years, and for each fraction of a year, days. I won't mess with months because they can have variable length,
14
6437
by: Paul Moore | last post by:
I was just writing some code which did date/time manipulations, and I found that the Python 2.3 datetime module does not supply a number of fairly basic functions. I understand the reasoning (the datetime module provides a set of datatypes, and doesn't attempt to get into the murky waters of date algorithms) but as these things can be quite tricky to get right, I was wondering if anyone has already implemented any date algorithms, or...
4
9341
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the datetime strftime() methods require year >= 1900 Does anyone know of a datetime string formatter that can handles strftime format strings over the full range that datetime objects support?
2
2834
by: BRIAN | last post by:
I am tyrying to use the System.IO.File.GetCreationTime name space to get the creation date of a file. That's no problem. I want to delete a file if it is older than two weeks. For Each File1 In Directory.GetFiles("c:\Test") If CreationDate < (System.DateTime.Now( ) - 14) Then File.Delete(File1) End If
2
283
by: PK9 | last post by:
I have a loop where I need to calculate a series of dates based on: 1) a start date (DateTime variable) 2) a number of days (integer variable) I need to take the start date, then add the number of days to it, and come up with the next date. eg. - DateTime variable might equal 01/02/2005 - My integer for "Number of Days" is 10
2
4556
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
3
2902
by: planetthoughtful | last post by:
Hi All, I'm trying to determine the number of days between today and the value in a datetime field in a table. It appears my version of MySQL doesn't have DATEDIFF available, so I'm wondering if there's another method to achieve the same result as: SELECT DATEDIFF(CURDATE(),`mydate`) AS numdays FROM tblArticles WHERE artid = 10
4
5507
by: Greg Scharlemann | last post by:
I have a series of records in a database. When each record is stored, the datetime is logged: $date = date("Y-m-d H:i:s"); Prior to adding a new record to the database, I want to run a query to retrieve all of the records uploaded in the last 7 days. I thought it would be easiest to: Pseudo Code: $newDate = $date - 7 days; select * from TABLE where DATE $newDate;
0
16509
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or date math in your T-SQL code. create function DateOnly(@DateTime DateTime) -- Returns @DateTime...
0
9633
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10305
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9928
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7483
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.