I am very new in C# and I have a doubt.
In an application on which I am working I found something like it in the code:
if (!String.IsNullOrEmpty(u.nome))
This code simply check if the nome field of the u object is not an empty\null string.
Ok this is very clear for me, but what can I do to check it if a field is not a string but is DateTime object?
SELECT * FROM employe WHERE date IS NOT NULL AND (date > ? AND date < ?) We first check if the date is null. If this condition its true, then it will check if the date is inside the range.
Use the value property to check if an input type="date" is empty, e.g. if (! dateInput. value) {} . The value property stores the date formatted as YYYY-MM-DD or has an empty value if the user hasn't selected a date.
DateTime itself is a value type. It cannot be null.
Try setting the value of the date to 0000-00-00, this usually works (never tried it in this scenario but everywhere else it always worked for me). @AlonAlexander ah if only.
If you declare a DateTime, then the default value is DateTime.MinValue, and hence you have to check it like this:
DateTime dat = new DateTime(); if (dat==DateTime.MinValue) { //unassigned }
If the DateTime is nullable, well that's a different story:
DateTime? dat = null; if (!dat.HasValue) { //unassigned }
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