Hello I am having the same problem even after I tried upper solutions.
- I make a string with datetime.now.tostring
- then I make a date variable with parseexact using string made in step one
- then after I make a new string with datevariable.tostring
Hello I am having the same problem even after I tried upper solutions.
Why are you trying to do that? Just testing things?
This picture is testing, but in real code, I need to take a date from excel, and substract 6 days to send a mail on new date(6 days before). I find out that its the problem in excel variable type
ParseExact expects valid format string matching the content of the input string.
In your case the format string is likely invalid.
Better use CDate() function.
Cheers
Date value in Excel is not Datetime but OADate
What to do in that case? I’m receiving that excel from HR and maybe it’s not possible for them to change format cause program is generating that file for them. CDate() is not working.
Best Regards
EDIT:
I’ts not the same problem
So here it is string, right?
What is the format of the string? Is is “dd.MM.yy”?
When i type a string inside ParseExact like DateTime.ParseExact(“07.01.20”,“dd.MM.yy”,Globalization.CultureInfo.InvariantCulture).AddDays(-6)
It is working
but when i put assigned string from excel(it seems as same format,look in the picture) it doesn’t work
DateTime.ParseExact(strDate,“dd.MM.yy”,Globalization.CultureInfo.InvariantCulture).AddDays(-6)
It is working
Check for any leading/trailing spaces/tabs etc. in the string from excel. It’s often a problem.
also pay attention that your excel has one blank first line…
Im making working copy DT from original excel, so it maybe makes wrong types