I am absolutly new in C# (I came from Java) and I have a very stupid problem
I have to initialize some DateTime fields into an object but I have some problems doing it.
In particular I am trying to inizialize these fields in this way:
mySmallVuln.Published = '1998,04,30'; mySmallVuln.LastUpdated = '2007,11,05';
But Visual Studio sign me it as error
Too many characters in character literal
What am I missing? How to solve it?
someDate = null; myCommand. Parameters. AddWithValue("@SurgeryDate", someDate);
The default and the lowest value of a DateTime object is January 1, 0001 00:00:00 (midnight). The maximum value can be December 31, 9999 11:59:59 P.M. Use different constructors of the DateTime struct to assign an initial value to a DateTime object.
To set dates in C#, use DateTime class. The DateTime value is between 12:00:00 midnight, January 1, 0001 to 11:59:59 P.M., December 31, 9999 A.D. Let's create a DateTime object.
Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time. public: static property DateTime Now { DateTime get(); }; C# Copy.
mySmallVuln.Published = new DateTime(1998,04,30);
Or perhaps like this
var date = DateTime.MinValue; if (DateTime.TryParse("1998/04/30", out date)) { //Sucess... mySmallVuln.Published = date; }
DateTime d = default(DateTime);
The default keyword works for all data types too!
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