matthew fabrie
matthew fabrie

Reputation: 103

html string to js script

i'm new to HTML and JavaScript but i have to change a string which represents a date in this format: DD/MM/YYYY HH:MM:SS to this format: DD/MM/YYYY HH:MM. I am trying to get the value of {{msr.start}} inside of my javascript function so that i can use the slice() function to make it 3 characters shorter, can anyone please tell me how i can get the value of {{msr.start}} inside of my script? Thanks in advance :)

<td colspan="4" class="text-center text-middle" id="abc123">
  {{msr.start}} <--- this contains the right date and time
  <script>
    var tmp = {{msr.start}}.splice(0, 3) <--- here is where i want to use the date and time
    document.getElementById('abc123').innerHTML = tmp
  </script>

Upvotes: 0

Views: 88

Answers (1)

Timothy Alexis Vass
Timothy Alexis Vass

Reputation: 2705

You can use let tmp = "{{msr.start}}" and then use substring() Example:

let tmp = "DD/MM/YYYY HH:MM:SS" //You would use "{{msr.start}}"

console.log(tmp.substring(0, tmp.length - 3));

Upvotes: 2

Related Questions