Questions tagged [hour]
457 questions
254
votes
12 answers
Extracting hours from a DateTime (SQL Server 2005)
I can extract the month and day by using Day(Date()), Month(Date()). I can't extract hours, with HOUR(Date()). I get the following error.
'HOUR' is not a recognized built-in function name.
How can I extract hours?
Efe
117
votes
9 answers
How do I get hour and minutes from NSDate?
In my application I need to get the hour and minute separately:
NSString *currentHour=[string1 substringWithRange: NSMakeRange(0,2)];
int currentHourInNumber=[currentHour intValue];
Consider string1 contains 11:59:13 AM which is coming from…

mac
- 4,760
- 7
- 31
- 33
92
votes
13 answers
Add 'x' number of hours to date
I currently have php returning the current date/time like so:
$now = date("Y-m-d H:m:s");
What I'd like to do is have a new variable $new_time equal $now + $hours, where $hours is a number of hours ranging from 24 to 800.
Any suggestions?

Jonah Katz
- 5,230
- 16
- 67
- 90
83
votes
3 answers
Java getHours(), getMinutes() and getSeconds()
As I know getHours(), getMinutes() and getSeconds() are all deprecated in Java and they are replaced with Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND.
These will in fact return the hour, minute and second for that particular moment.…

mel
- 831
- 1
- 6
- 6
64
votes
3 answers
Python: get datetime of last hour
I want to get the date time object for last hour.
Lets say the sys time is "2011-9-28 06:11:30"
I want to get the output as "2011-9-28 05" #{06 - 1 hour}
I used:
lastHourDateTime = date.today() - timedelta(hours = 1)
print…

Rishav Sharan
- 2,763
- 8
- 39
- 55
56
votes
2 answers
Regex pattern for HH:MM:SS time string
I want to parse a hh:mm:ss string.
A simple one is ([0-1]?\d|2[0-3]):([0-5]?\d):([0-5]?\d) which expects 2:3:24 or 02:03:24 string.
I want to take it a step further and pass the validation even in cases like
if you enter just 56, it should be…

user418836
- 847
- 3
- 8
- 19
54
votes
11 answers
Subtract n hours from a DateTime in Ruby
I have a Ruby DateTime which gets filled from a form. Additionally I have n hours from the form as well. I'd like to subtract those n hours from the previous DateTime. (To get a time range).
DateTime has two methods "-" and "<<" to subtract day and…

Tillmann Carlos Bielefeld
- 543
- 1
- 5
- 4
47
votes
2 answers
Convert time to 24 hours format in Javascript
How can I isolate and convert the local time format in JavaScript's new Date() to a 24 hour format?
Example: 2016-09-22T23:21:56.027Z just becomes 22:56 in local time.

Kishh
- 2,005
- 4
- 19
- 16
33
votes
4 answers
How do you set the time and only the time in a calendar in Java?
Having the hours and minutes, is there any easier or better way to set it into a Calendar object than:
calendar.set(calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
…

Pablo Fernandez
- 279,434
- 135
- 377
- 622
24
votes
8 answers
How to know if now time is between two hours?
I have a now time:
new Date();
And I have some hour constants, for example, 23 and 8 (it's 11pm or 23:00, 8am or 08:00).
How I can know is now time between it's two hour constants?
It need to run some code of program or not to run if now time is…

Trancer
- 765
- 2
- 8
- 23
24
votes
10 answers
Changing the 1-24 hour to 1-12 hour for the "getHours()" Method
When I use the "getHour()" method in javascript, it displays the military time format. I need it to display the hour in numbers between 1-12 instead. Can anybody tell me how to do this? Here is the code I am using:
function updateclock()
{
…

Tony Wilkerson
- 351
- 1
- 2
- 4
18
votes
1 answer
Android - Find out what hour of day it is
I want to use and alarmManager that sets a repeating alarm to go off on the hour, every hour. I know how to set a repeating alarm every hour but not how to actually set it from the top of the hour, I need to know this value for the 'whatTime'…

bobby123
- 1,006
- 4
- 14
- 24
18
votes
4 answers
How to update only the hour from a DATETIME field in MySQL?
I want to update a DateTime column where it will change the hours only without modifying anything else. I can't use to add an interval as the values all are different. There is many different dates too. So need to change the hour of exact desired…

M.A.K. Ripon
- 2,070
- 3
- 29
- 47
17
votes
7 answers
How to do a cron job every 72 minutes
How would I get a cron job to run every 72 minutes? Or some not so pretty number like that?
smith
16
votes
2 answers
How do I add 1 hour to datetime SQL column data?
I used this part of a query to create a table column for the date and time a row is added:
order_date datetime NOT NULL DEFAULT GETDATE()
and whenever a new row is created, the data for order_date is set to something like this:
Apr 8 2014 9:52AM
For…

Kelsey
- 913
- 3
- 19
- 41