943,640 Members | Top Members by Rank

Ad:
Jun 24th, 2008
-1

code to add 15 days to a given date.

Expand Post »
M writing a program to display the date ie. 15 days later after a given (present/todays)date.
Wel its actually like this. As soon as i write todays date, in the next text box, the date shd be automatically displayed adding 15 days to the present date which is already displayed.
Eg. supose i enter 01/06/2008 (dd/mm/yyyy), it shud automatically display 15/06/2008.
M trying to use
Datediff() function, but i dont know how to go about.

can anyone plz help me with the code..?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
chanthung is offline Offline
52 posts
since Jun 2008
Jun 24th, 2008
0

Re: code to add 15 days to a given date.

In C#:

string strDate = "20/10/1983";
DateTime date = DateTime.Parse(strDate);
string newDate = date.AddDays(15).ToShortDateString();
Reputation Points: 10
Solved Threads: 1
Newbie Poster
nagasai is offline Offline
1 posts
since Jun 2008
Jun 24th, 2008
0

Re: code to add 15 days to a given date.

Hi,

Use DateAdd function

vb Syntax (Toggle Plain Text)
  1. Dim TDate As Date
  2. TDate = CDate("01-06-2008")
  3. MsgBox DateAdd("d", 15, TDate)

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Jun 24th, 2008
0

Re: code to add 15 days to a given date.

Similar to Veena, I give another way

VB Syntax (Toggle Plain Text)
  1. Dim TDate As Date
  2. TDate = Date
  3. MsgBox TDate + 15
Still same result

Note:
Date object plus number will work only for days addition, but DateAdd() function will work for any interval
Last edited by selvaganapathy; Jun 24th, 2008 at 12:27 pm.
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Jun 25th, 2008
0

Re: code to add 15 days to a given date.

Thanks lots to all of u for help. M on it right away. Actually i'll be taking the date from the user tru da text box (n tn accept it in a string i suppose..)and try to add using the DateAdd function. The new date will be displayed in the next textbox. So after say 15 days it shud display a msg or change the background color i gs. M using Grid Control layout to display the Datas. MS Access is my database.

Have a Wonderful day ahead!!!!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
chanthung is offline Offline
52 posts
since Jun 2008
Jun 25th, 2008
0

Re: code to add 15 days to a given date.

made it this way.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Text5_Lostfocus()
  2. Dim PDate, RDate As Date
  3. PDate = CDate(Text5.Text)
  4. RDate = DateAdd("d", 15, PDate)
  5. Text6.Text = RDate
  6. End Sub
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
chanthung is offline Offline
52 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: sound recording through vb program?
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: How to get "user account"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC