0

So I am just logging to my database and provide the date. My C# backend is like so.

var dateAndTime = DateTime.Now;
log.Date = dateAndTime.Date;

I then submit it to my db and it displays perfectly from select statements inside Microsoft SQL Server Management Tool 2014.

I load it through javascript like so it by so

LoaderService([
  {
    name: 'logs',
    url: $config.serverAddress + 'Logs/GetAllLogs',
    error: 'cantloadlogs'
  }
]).response(function(isReady, data, errors) {
  $scope.isReady = isReady;
  $scope.isError = errors.length > 0;
  $scope.errors = errors;
  if (isReady) {
    $scope.logs = data.logs;
    return console.log(data.logs);
  }
});

I then display it through HTML in an ng-repeat like so.

<td id="logs--row-{{$index}}-column-3">{{log.Date}}</td>

But when I actually view my web page the date displays in this format.

2019-06-05T00:00:00

Can anyone explain where T00... is coming from and how to stop it?

Another point to note I am storing it in my database as a date attribute.

Dan Murphy
  • 225
  • 1
  • 5
  • 15
  • 1
    https://stackoverflow.com/questions/8405087/what-is-this-date-format-2011-08-12t201746-384z and https://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript – Pete Jun 05 '19 at 16:13
  • Possible duplicate of [What is this date format? 2011-08-12T20:17:46.384Z](https://stackoverflow.com/questions/8405087/what-is-this-date-format-2011-08-12t201746-384z) – esqew Jun 05 '19 at 16:15
  • It's standard ISO8601 date format. As you can probably figure out, the T starts the time portion. C# DateTime objects always have a time (even if it's not specified in the database field which populated the object, hence why you're just seeing midnight every time). And when they're serialised to JSON this is the default format which is used in the serialisation process. You could potentially use JS to reformat them before displaying. – ADyson Jun 05 '19 at 16:15
  • 3
    Change `{{log.Date}}` to `{{log.Date | date:'yyyy-MM-dd'}}` – Rand Random Jun 05 '19 at 16:23
  • @RandRandom You hero, thank you that worked. – Dan Murphy Jun 05 '19 at 16:25

1 Answers1

2

Change {{log.Date}} to {{log.Date | date:'yyyy-MM-dd'}}

Have a look at the following documentations:

  1. https://docs.angularjs.org/api/ng/filter/date
  2. https://www.w3schools.com/angular/ng_filter_date.asp

Consider using {{log.Date | date:'shortDate'}}

if you don't want to force a specific Format but rather have it dependent on the regional settings of your user.

Rand Random
  • 7,300
  • 10
  • 40
  • 88