In the Controller Page:
maLeads.Cdate = DateTime.Now;
In the Model Page:
public Nullable<System.DateTime> Cdate { get; set; }
when i use the .ToString("dd/mm/yyyy") and .ToShortTimeString format gives error. Can someone help me with this problem, please?
Probably because you're calling .ToString()
from a null instance; you should go with
CDate.HasValue ? CDate.Value.ToString("dd/MM/yyyy"): ""
This will not remove the time part from your DateTime?
object, but maybe you don't need that. If so, use the .Date
property.
Also, notice you're using the wrong date format: " mm
" means "minutes", not months (" MM
")
Try this
var dateAndTime = DateTime.Now;
var date = dateAndTime.Date;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.