Bob2
(Bob)
1
Hello
Is there any way to change a string I am pulling from a data table which is a date into a date format variable?
The string variable is below
Which writes as a sting like below
I then want to convert this to a date variable like below
This is the error I am getting
1 Like
@Bob2 Do you want only Date , or Date with Time as well?
1 Like
Hi @Bob2
You can check this out !
string.Format(“{0}”, System.DateTime.Now.ToString(“yyyy-MM-dd_hh-mm-ss”))
cheers :smiley
Happy learning
2 Likes
Bob2
(Bob)
5
I am still getting the error after the change
error
Bob2
(Bob)
6
I think its because I need the date format to be 16/01/2020
if(DateTime.TryParseExact(yourString,“MM/dd/yyyy hh:mm:ss”, Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, Nothing),DateTime.ParseExact(yourString,“MM/dd/yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture).toString(“dd/MM/yyyy”),Nothing)
This Code Checks if it is in a Required Date Format and then if it is true,Converts it into the Format Needed
3 Likes
Bob2
(Bob)
8
So put this into the ‘startDate’ variable like below but I am still getting an error
error
@Bob2 Can you remove the .ToString(“dd/MM/yyyy”) and Check
ashley11
(Ashley Nihal Dcunha)
10
try using this
variable must be of DateTime type
DateTime.ParseExact(RecievedDate,“dd/MM/yyyy”, nothing)
2 Likes
ashley11
(Ashley Nihal Dcunha)
12
good to hear that.
Happy Programming.
system
(system)
Closed
13
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.