Hello everyone i want to find difference of two dates but i am getting an error. can anyone can guide me how to resolve it.
Conversion from string “27-07-2023” to type ‘Date’ is not valid.
Kindly go through the attached image.
Hello everyone i want to find difference of two dates but i am getting an error. can anyone can guide me how to resolve it.
Conversion from string “27-07-2023” to type ‘Date’ is not valid.
Kindly go through the attached image.
@Ashish_Tyagi show me how you are converting from string to date
@Ashish_Tyagi
Show me your both date format.
Instead od cdate use this
Datetime.ParseExact(datevar,"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture)
If the format is different then change this accordingly dd-MM-yyyy
Cheers
Format for both the dates are same. dd-MM-yyyy
@Ashish_Tyagi
Try this
Cint(DateDiff(DateInterval.Day, Datetime.ParseExact(Today_date,“dd-MM-yyyy”,System.Globalization.CultureInfo.InvariantCulture),Datetime.ParseExact(Invoice_Date,“dd-MM-yyyy”,System.Globalization.CultureInfo.InvariantCulture)))
Try this one
@Ashish_Tyagi Ok try above one.
Replace inverted Commas with this "
@raja.arslankhan
It is showing the below error.
Cint(DateDiff(DateInterval.Day,Datetime.ParseExact(Today_Date,"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture),Datetime.ParseExact(Invoice_Date,"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture)))
Please use the above provided one…and this error is because of wrong inverted comma…change them in code
correct: "
wrong: ”
cheers
@Ashish_Tyagi
Try to convert inverted Commas “” as Anil mentioned. When we write here it changes to wrong one.
Cint(DateDiff(DateInterval.Day,Datetime.ParseExact(Today_Date,"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture),Datetime.ParseExact(Invoice_Date,"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture)))
@Anil_G
I got that earlier. Can you please explain the reason why it was not working using Cdate?
@Anil_G Because your date format contains dash format like “dd-MM-yyyy”
@Ashish_Tyagi
If your problem solved then mark it as a solution so that others can get help from it. Thanks
Cdate by default converts the date which is in your system date format only…any other formats need to be converted using parseexact method…
hope this helps
Cheers
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.