Jesus
Jesus

Reputation: 475

input type time is a string or datetime?

I'm working on Angular (front-end) with C# (back-end) project going, and I'm going to use the input time <input type="time">

So, is the value a string, or should I save it as DateTime and get the time part only?

How should the property be on the backend and database?

public DateTime? Property { get; set; }

Or

public string Property { get; set; }

Upvotes: 0

Views: 728

Answers (1)

Rikudou En Sof
Rikudou En Sof

Reputation: 758

Save to Database in DateTime, do all business logic in DateTime, but when you want to display to view, it is smooth to convert to string. Bellow is a sample code that i use to help with this.

 public string DateTimeToString(DateTime dateTime)
{
  var stringDate = dateTime.ToString("dddd, dd/MM/yyyy HH:mm");
  return stringDate;
}

You can format it however you wish, this will help to keep your DateTime on tables to look uniform, and removes the need to always convert to string at the presentation layer.

Upvotes: 1

Related Questions