nightingale2k1
nightingale2k1

Reputation: 10335

How to change from iso date to just plain date ? (nebular datepicker)

I use nebular datepicker on my project, on backend we just need the date only without hour and min, so we trim the date. but nebular sending the date on iso date format. thats the problem. When I type like Jul 23 2021, the date in my form formated like 2021-07-22T17:00:0000Z On the server, we got 2021-07-22 instead of 2021-07-23 So I need way to solve this? Can I have setting in nebular to disable the iso format ?

ps: i use angular 11, nebular from ngx-admin

Sc from frontend:

Frontend

sc from backend: (Dotnet C#)

Backend

Upvotes: 0

Views: 893

Answers (2)

n1cK
n1cK

Reputation: 368

Allegedly, you can use NbDateFnsDateModule to provide a format for your date, I could not get it working though personally.

EDIT: It worked for me providing the format in such an escaped way: format="'DD[/]MM[/]YYYY'", e.g.

  <nb-datepicker 
                  #datepickerLeft 
                  format="'DD[/]MM[/]YYYY'"
                  (dateChange)="setCorrectDate($event, field.name, 'datepicker');"></nb-datepicker>

EDIT 2: If the first one doesn't work, try this format: format="dd-MM-yyyy"

Upvotes: 0

iftikharyk
iftikharyk

Reputation: 959

Since you only need a date and not date-time combined I would suggest that you trim the ISO format date to a normal date string like this:

let dateFromInput = "2013-08-03T02:00:00Z";
let newDate = dateFromInput.substring(0, 10);

console.log("dateFromInput ", dateFromInput);
console.log("newDate ", newDate); // 2013-08-03

Upvotes: 1

Related Questions