Computing Hours From Time Stamps
Some data sets may contain time stamps in the format hh:mm:ss AM(PM), and it may be necessary to band these times together based on 24-hour time. For example, the analysis may require you to group respondents into 4-hour categories throughout the day. Q does not have a concept of time in the same sense as it has the concept of Date.
Where you have a text variable
When given a Text Variable (which we assume has the Variable Name TIME) containing time values in the format hh:mm:ss AM(PM), the following code will convert the values into values 1-24, which facilitates grouping of the values:
var _time_value = TIME; var _split_values = _time_value.split(":"); var _hour = parseInt(_split_values); if (_time_value.indexOf("PM") > -1) _hour = _hour + 12 _hour
Where you have a Date variable
- Use the Expression of Q.Hour(date_variable), where date_variable is the name of your date variable.
- Press OK.