I have a back-end written in Java and a front-end written in Angular. I pretend to show the age of an user doing maths (actual date - birth date) but I can't find a way to do that.
I tried this two options:
1.- Front-end: I do the maths and get the result. The problem is that the types do not look the same. If I print both this is the result:
- BirthDate: "1996-07-24T00:00:00.000+0000" (I got it from API)
- ActualDate: "Sat Jul 11 2020 20:27:02 GMT+0200 (Central European Summer Time)" (I got it doing let date: Date = new Date;)
When I use any function with the birthdate I got an error. for example getTime() to get it in miliseconds. Both variables are stored in Date type variables. Errors looks like this:
ERROR TypeError: user.birthDate.getTime is not a function
at SafeSubscriber._next (user-list.component.ts:47)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
at SafeSubscriber.next (Subscriber.js:122)
at Subscriber._next (Subscriber.js:72)
at Subscriber.next (Subscriber.js:49)
at MapSubscriber._next (map.js:35)
at MapSubscriber.next (Subscriber.js:49)
at FilterSubscriber._next (filter.js:33)
at FilterSubscriber.next (Subscriber.js:49)
at MergeMapSubscriber.notifyNext (mergeMap.js:72)
2.- Backend. I added a new attribute in the class and I called it Age. I do not want to store it in the DB I just want to calculate it and give it to the front-end. with this, looks like Java tries to share this new attribute but it is not in the DB because I do not want to store it. I thought that If I do not add the @Column above the attribute, it would not connect to a column in the database but looks like it does not work.
Any ideas? I accept any of the 2 approaches.
Thank you