Need help setting default date to previous sunday

johncassell

Well-known member
Joined
Jun 10, 2007
Messages
120
Location
Redcar, England
Programming Experience
Beginner
Hi There,

I have a problem on a form and, although I could probably work out a way to do it, i know for a fact it would be very long winded and was hoping some clever chap could help me with a simpler version.

What I need:

I have a form with a datetimepickerbox. When the form loads, the date in the box is todays date. I need it to be the date of the previous sunday.

Example: Today is Sunday, 17th June. Datebox displays 17th June.
Today is Saturday 16th June. Datebox displays 10th June.


Could anyone help with this please?

Thanks

John
 
Last edited:
I posted something I found for someone regarding setting a DTP to the 1st Monday of the month - it'll no doubt be very similar to that.

Search on Google for "vb.net datetimepicker previous week" or along those lines to see what comes up...the website I found (which I didn't make note of) showed how to do pretty much anything with the DTP...
 
VB.NET:
        Dim d As Date = Date.Now
        DateTimePicker1.Value = d.AddDays(-1 * d.DayOfWeek)
 
Back
Top