I have two input fields to search between dates. I want the start date to default to the first day of the current year and the end date to default to today. I have the end date but I am unsure of how to get it to display the start.
var defaultStart = var defaultEnd = moment((new Date()).valueOf()); $('#searchStart').val(defaultStart.format('DD/MM/YYYY')); $('#searchEnd').val(defaultEnd.format('DD/MM/YYYY'));
Calling format('YYYY') will invoke moment's string formatting functions, which will parse the format string supplied, and build a new string containing the appropriate data. Since you only are passing YYYY , then the result will be a string containing the year. If all you need is the year, then use the year() function.
You could do this:
moment().startOf('year');
format by doing something like this:
moment().startOf('year').format('MM/DD/YYYY');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With