I hope you can help.
I have a console application that needs to receive a datetime value, so for example 2015-12-01 00:00:00.000, but the time part does not get picked up because of the space between the date and the time. I have 3 variables I am passing : (2 integers and 1 Datetime)
Cmd Prompt :
C:\Application1.exe 3935 1 2015-12-01 00:00:00.000
Is there a way I can pass through the date and time as 1 variable, like '2015-12-01 00:00:00.000' ?
Ive tried everything, but nothing seems to work.
Sure, encapsulate it into quotes and parse it from a string:
var myDate = DateTime.Parse(args[2]);
Or a saver appraoch would be using DateTime-TryParse:
var date = DateTime.Now;
if (DateTime.TryParse(out date)) { /* do anything with the date */ }
Call it like:
C:\Application1.exe 3935 1 "2015-12-01 00:00:00.000"
Add a T
:
C:\Application1.exe 3935 1 2015-12-01T00:00:00.000
This should work if you use DateTime.Parse
to convert and you won't have to mess with spaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With