This might be really easy but I can't figure it out. I am trying to convert the 24 hr time to a 12 hr time to display on the UI.
var hrs = '<%=Model.Scheduled.Value.Hour%>';
var hrs12 = hrs > 12 ? hrs - 12 : hrs;
$("#ScheduledHour").val(hrs12);
But the above is not working coz hrs is a string. Any suggestions on how to get this working?
you can use parseInt():
var hrs = '<%=Model.Scheduled.Value.Hour%>';
hrs = parseInt(hrs, 10) // converts the value to an integer
var hrs12 = hrs > 12 ? hrs - 12 : hrs;
$("#ScheduledHour").val(hrs12);
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