I have a registration form that asks the user for their start date. I am using a MEAN Framework which means Im using AngularJs on the front end.
What I have done so far:
First I tried using the following code BUT it does not work on IE & FireFox.
<input type="date" name="startDate">
Then I tried the following REGEX that I found on this SO question.
^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
The works perfectly. Below is an image of how it works in my app.
The Issue:
When the user submits the form the data is saved in MongoDB. In the above image you can see that data is saved as a string. I want to convert it to a proper Date format so I can perform actions on it server side (Node.js) i.e filter all users who started after 2015 or left between 1999 & 2001 etc.
Any suggestions would be helpful.
UPDATE:
Currently I am testing moment.js. Will update my question once I have a result.
Result:
I tried the following using moment.js:
console.log("MOMENT" + moment("1993-03-25").format());
The output of the following was:
MOMENT 1993-03-25T00:00:00+00:00
I am not sure whether this is the correct format to be saved in MongoDB and will it allow me to perform server side actions on it.