I’m trying to modify a retrieved date ex: 2013-01-20 00:59:06 by adding +1 to the day if the time is less than 20:00. The reason is that if the time retrieved is less than 20:00, it means that it must be then somewhere between 00:00 and 07:00 – meaning it’s the next day.
Here is what I did:
var WhenDateUnformatted = $('#when').val().split('/');
var startTimeSPLIT = startTime.split(':');
if (WhenDateUnformatted[1] < 20) {
var WhenDateUnformatted[1] = WhenDateUnformatted[1] + 1;
}
var WhenDate = WhenDateUnformatted[2] + '-' + WhenDateUnformatted[0] + '-' + WhenDateUnformatted[1] + ' ' + startTime + ':00';
The error I receive is:
SyntaxError: missing ; before statement
var WhenDateUnformatted[1] = WhenDateUnformatted[1] + 1;
It doesn’t like the [1]
Does that mean I have to convert WhenDateUnformatted[1] to an individual variable first if I want to do anything with it?
Thanks! 🙂
Edit: I made a mistake, the first part should be
if (startTimeSPLIT[0] < 20) {
You are re-declaring WhenDateUnformatted. Just assign it a value inside your if statement.
In response to your comment and to update in accordance with Robrich’s input, I have updated the code.