2

I have an element in html5:

<input class="form-control" #semana="ngModel" name="semana" [(ngModel)]="detalle.semana" type="week">

The value I get is a string "2018-W23" for example. What I want is to get the value in date or number entered to perform operations on it (add or subtract days) and save it in my database.

I am working with Angular 5, JAVA spring and MySQL

NicoGuevaraAtuq
  • 502
  • 2
  • 5
  • 17

2 Answers2

2

You need a conversion function to get a Date object from your week input.

See this discussion : javascript calculate date from week number

It appears there is no standard JS function to do that, so you have to implement your own function (again, see discussion - link above) to parse the week input into a Date object.

Then with your Date object it will be convenient to do operations (add days etc) and save it to your database.

Air1
  • 567
  • 3
  • 6
0

For anyone looking how to do it in Javascript, you can easily do so using moment.js.

moment( document.querySelector("#weekInput").value ).format("yyyy/MMMM/DD")
H3lltronik
  • 562
  • 8
  • 26