VB.NET Date Functions Calculations [modified] - SOLVED
-
Hi I have DatePicker and the Maxdate is set to today: I am struggling with the MinDate. I need to set the Mindate to the 1st of 3 Months back(Keep in mind that the current month will be 3rd Month). Ex.1 For instance if we work it out as today the MinDate has to be: 01 January 2010 Ex.2 if today is the 16th of April 2010 the min date has to be: 01 Feb 2010 I hope someone can help me with this as I am really struggling with this calculation Thank you in advanced
modified on Tuesday, March 30, 2010 5:39 AM
-
Hi I have DatePicker and the Maxdate is set to today: I am struggling with the MinDate. I need to set the Mindate to the 1st of 3 Months back(Keep in mind that the current month will be 3rd Month). Ex.1 For instance if we work it out as today the MinDate has to be: 01 January 2010 Ex.2 if today is the 16th of April 2010 the min date has to be: 01 Feb 2010 I hope someone can help me with this as I am really struggling with this calculation Thank you in advanced
modified on Tuesday, March 30, 2010 5:39 AM
I think this is what you want
minDate = DateAdd(DateInterval.Month, -2, Today)
minDate = DateAdd(DateInterval.Day, (Today.Day - 1) * -1, Today)Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
-
I think this is what you want
minDate = DateAdd(DateInterval.Month, -2, Today)
minDate = DateAdd(DateInterval.Day, (Today.Day - 1) * -1, Today)Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
Thank you Steven, but if I work it from todays day it should be 01/01/2010 but the result your code gives is 3/1/2010. I do appreciate your effort in helping.I'll try to work with this code and try to change it. Thank you so much
-
I think this is what you want
minDate = DateAdd(DateInterval.Month, -2, Today)
minDate = DateAdd(DateInterval.Day, (Today.Day - 1) * -1, Today)Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
Thank you so much Steven I have changed the second line of code and replaced today with mindate and its working perfect. Im just wondering now what would happen if this month has 31 days and 3 months back has only 30.
-
Thank you so much Steven I have changed the second line of code and replaced today with mindate and its working perfect. Im just wondering now what would happen if this month has 31 days and 3 months back has only 30.
Member 4420534 wrote:
Im just wondering now what would happen if this month has 31 days and 3 months back has only 30
Either reset your system clock to an appropriate date (not forgetting Feburary only has 28 days or 29 on Leap years). Define a DateTime varable and use the DateSerial function to populate it with your test date, then use the testing dateTime variable instead of the current system date, to test your code.
Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.