Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Increment date after initial date?

Author  Topic 

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-11 : 13:39:42
I'm just curious how to increment in a existing date after so many days. For example I have a date that's 01/01/2005, after 2 days of the previous date, I want it to populate like 01/03/2005.

I can increment numbers but I'm not sure how to do it with date. Any examples or advice is much appreciated.

jhermiz

3564 Posts

Posted - 2005-04-11 : 13:41:44
DateAdd function

Response.Write(DateAdd("d", -365, Date)


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-11 : 14:00:33

Wow that was simple. Another question, how would i have it populate after 2 days though?

Looks like the DateAdd Function will add in date base on the system date, but how could I get it to add base on the initial date.

Example:

01/01/2005 is now populated to a new field 01/03/2005 base on the initial date of 01/01/2005.

Any ideas.
Go to Top of Page

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-11 : 14:05:14
Maybe this might work. Correct me if I'm wrong.

Response.Write(DateAdd("d", 2, strDate)

I have the initial date stored in a string and then add two to the day and then populate the field. Is my assumption correct?
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-04-11 : 14:09:54
Yes but be care ful with strings, you may need to convert to a date to get the correct value and CSTR() back to a string for presentation reasons.




Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-04-11 : 14:13:15
Format(DateAdd(DateInterval.Day, 2.0, Now), "dd-MMM-yy")

Now is of type date. So try:

Response.Write(DateAdd("d", 2, CType(strDate, Date)))



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-12 : 14:29:37
Thanks. That works great.

Quick question. To compare date, do you use the date function to or is there a compare date? For example I want to compare the initial date and if it's passed 2 days then go and do the adddate function. Any ideas?
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-04-12 : 16:04:29
You can use DateDiff, look up Date functions in the .net help section you will find a wealth of date functions that are worth using.




Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-19 : 10:35:44
Thanks Jeff. There's a lot of information there that I didn't realize where there.
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-04-19 : 10:40:03
Its JON not JEFF :).


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-19 : 10:42:27
Sorry Jon. I must've lost my mind a while back.
Go to Top of Page
   

- Advertisement -