Date Formatting

winsonlee

Member
Joined
Jan 5, 2008
Messages
10
Programming Experience
Beginner
Dim date as string

date = '080303'

How can i do newdate = date - 21 days ?
 
You would need to declare the date as a datetime, not a string.

VB.NET:
Dim dt As DateTime
        dt = DateTime.Parse("03/03/08")
        dt = dt.AddDays(-21)
        MessageBox.Show(dt.ToShortDateString())
 
Asking users to input date in "080303" format is always confusing. I suggest you ask them to input date in "3 Mar 08" format. You can easily parse the date correctly. When you output the date to user, you can use yourOutputDate.ToString("dd MMM yy").
 
Asking users to input date in "080303" format is always confusing.
This thread is probably not about asking user to input date in writing, but in that case you should use a DateTimePicker.
 
Back
Top