AngularFirebase Date Format

Hi Guys,

I am newbie to Angular and Firebase, but really liking it so far. The thing is I am stuck for 2 days in the date format, which must be easier. I am confused on datepicker. I am using:

<material-datepicker [(ngModel)] =“member.joineddate”>

While I use this, firebase saves the date as: Nov 24, 2017 at 12:00:00AM UTC…

How do I save just the date as, 11-24-2017 in firebase. I am showing the saved date in my view and in return whole timestamp value shows up. That looks quite bizarre, I just want to show the date. I should further be comparing the dates with the today’s date also, so having just the date could be more easier.

Anyone has any idea on this? Sorry, if this is too rookie one, having that burnout phase.

Have a look at the Date pipe:

Why would you want to save the date as that? The one you currently have is a universally understood ISO format. The second one isn’t (eg, where I live it’s just flat out wrong - there aren’t more than 12 months but you’re saying that date is the 11th day of the 24th month). If you think that is not really an issue, then try 11-12-2017. Is that the 12th of Nov or the 11th of Dec? If you save as the MM-DD-YYYY format, it is impossible to tell (you personally will know, but another person won’t, and the computer certainly won’t)

The second one is a particular representation of a date in a specific geographic locale. The first one is a detailed timestamp you would save in a database. You should parse the timestamp on the front end; the client should decide how to display it (that’s what the JS method toLocaleDateString is for).

JS lets you compare dates: new Date(myDate) > new Date(myOtherDate) or whatever.

Hi Ben,
Yes, Date pipe worked for me. Thanks.

Hi Dan,

The date I gave was just an example, I did not mean in that format. Sorry for the that. I got the date format like I wanted by using pipes.

I am looking forward to compare the dates in my view file.
Like, todaysdate = Nov 28, 2017. And, duedate=Oct 27, 2017. What exactly I am trying to is, if todaysdate > duedate, I want to change the color of the list.My code looks like this:

Today's date: {{todaysdate|date:'mediumDate' }}
  • NAME:{{}} Joined Date:{{member.joineddate | date:'mediumDate'}} Paid Date: {{member.paiddate | date:'mediumDate'}} Due Date:{{member.duedate | date:'mediumDate'}}

Thank you!