Micro Focus QTP (UFT) Forums
How to validate date in an application should not accept less than future date. - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to validate date in an application should not accept less than future date. (/Thread-How-to-validate-date-in-an-application-should-not-accept-less-than-future-date)



How to validate date in an application should not accept less than future date. - ruchi03 - 08-09-2014

Hi,

Recently i have been asked a question in an interview where,

I have to validate that the application should not accept the date less that the current date. hoe to write the VB script code for this?

The condition is application does not keep tracks of the date, but when i am entering the date it in a field and submitting the record it should not submit the record if the date is less than T+1. (T=current date).


Helps are much appreciated.

Thanks.


RE: How to validate date in an application should not accept less than future date. - rajkumarsm - 10-08-2014

Hope the below code works out

'I have to validate that the application should not accept the date less that the current date. hoe to write the VB script code for this?
Code:
inputdate = cdate(Inputbox("Enter Date"))   '10/8/2014
'msgbox inputdate 'displays user entered date
'msgbox date 'displays current date
If inputdate = date or inputdate > date then
'Browser("Browser").Page("Page").Frame("DatePicker").Set inputdate
msgbox "valid date "& inputdate
Else
msgbox "Date Should not be earlier than current date"
end if

'The condition is application does not keep tracks of the date, but when i am entering the date it in a field and submitting the record it should not submit 'the record if the date is less than T+1. (T=current date).
Code:
inputdate = cdate(Inputbox("Enter Date"))   '10/8/2014
'msgbox inputdate 'displays user entered date
'msgbox dateadd("d",1,date) 'displays current date + 1 day
If inputdate = dateadd("d",1,date) then
'Browser("Browser").Page("Page").Frame("DatePicker").Set inputdate
msgbox "valid date "& inputdate
Else
msgbox "Enter a valid date Eg. Current Date" & "(" & Date & ")" & "+1 Day " & "i.e.,"& dateadd("d",1,date)
end if