473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

I want to query of getting hour from date field

In my table the field of DateTime name is TIN. In this field DATE and TIME are shown for date I pass this query:
Expand|Select|Wrap|Line Numbers
  1. SELECT DAY(TIN) FROM SHIFT WHERE SHID = 1
Then the result is "10".

So the same I want to get Hour fromt his field I pass this query:
Expand|Select|Wrap|Line Numbers
  1. SELECT HOUR(TIN) FROM SHIFT WHERE SHID = 1
But it gives this error:
'HOUR' is not a recognized function name.
So please help me and give me the complete query from getting hour.
Oct 24 '09 #1

✓ answered by nbiswas

Either use DATEPART() or DATENAME()
e.g.

Expand|Select|Wrap|Line Numbers
  1. SELECT DATEPART(HH,GETDATE()) AS [Hour]
  2.  
  3. SELECT DATENAME(HH, GETDATE())AS [Hour]
Refer this articles for more infos

a) DateName( ) http://msdn.microsoft.com/en-us/library/ms174395.aspx

b) DatePart() http://msdn.microsoft.com/en-us/library/ms174420.aspx

Hope this helps

5 17648
code green
1,726 Expert 1GB
Because HOUR() expects a TIME data type
Oct 26 '09 #2
topher23
234 Expert 100+
If MySQL is anything like MS-SQL, it saves the date/time as a number along the lines of 1345.5467, where the whole number is the day and the fraction is the time of day. Performing a manipulation to pull the whole number off the fraction, then formatting the remaining decimal as a time value will accomplish the same result as the Hour() function.
Oct 26 '09 #3
Atli
5,058 Expert 4TB
Based on the fact that HOUR is a valid MySQL function, and that the error message matches that of a MSSQL server (as far as I know), I am going to assume this is in fact a MSSQL question posted in the wrong forum.

If that is the case try this:
Expand|Select|Wrap|Line Numbers
  1. SELECT DATEPART('hh',TIN) WHERE SHID = 1
However, It has been years since I used MSSQL, so this could very well be wrong. (Worth a try tho.)

I'll move this over to the MSSQL forum now.
Oct 31 '09 #4
ck9663
2,878 Expert 2GB
Use the datepart() function.

Happy Coding!!!


--- CK
Nov 1 '09 #5
nbiswas
149 100+
Either use DATEPART() or DATENAME()
e.g.

Expand|Select|Wrap|Line Numbers
  1. SELECT DATEPART(HH,GETDATE()) AS [Hour]
  2.  
  3. SELECT DATENAME(HH, GETDATE())AS [Hour]
Refer this articles for more infos

a) DateName( ) http://msdn.microsoft.com/en-us/library/ms174395.aspx

b) DatePart() http://msdn.microsoft.com/en-us/library/ms174420.aspx

Hope this helps
Nov 8 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joel | last post by:
Hi, How do you determine if a Date field is blank. In my Sql statement I only want records who's date field is blank (i.e. checking for only open invoices where Date_Paid = '' ...still open...
5
by: Bayla Frankl | last post by:
Hi all, I am a little stumped. I have a query I am trying to run to retrieve the last Progress Note record from the database for the current patient so that the therapists can see the last note...
2
by: Danny | last post by:
I have a table with an 'orderdate' field. this is a date type. I am trying to return all records that have an orderdate of within 30 days from todays date. The datediff in a sql query did not...
1
by: Dave Mann | last post by:
Right i have tried but failed! I have a Form and a subform Fields in Sub form are:- Planned - Checkbox Unplanned - Checkbox Maint Type - Dropdown selection Date Done Description
2
by: Winshent | last post by:
I have a dataset which is populated from a webservice. I want to filter a date field using DateTimePickers, but this just produces an error.. '########################################### If...
2
by: Igor | last post by:
Can someone tell me sql query for filtering date field for current day, not last 24hours but from 00:00 to current time?
7
by: sheri | last post by:
I have a field called date, the date is in the field like this 70925 (which means Sept. 25, 2007). I have another field called day, it is a text field. How do I write a query to populate the day...
10
by: Jes | last post by:
Dear all I have a date field on a HTML form where the user is asked to key in dd/mm/yyyy However, when that is written to MySql it is either not accepted or another value is tored in the...
1
by: Duggi | last post by:
Hi All, I want to apply a date field as filter for the Dataview. How shall I do it.. How to discribe a string for DataView.RowFilter ? DataView.RowFilter = ??????????????? What would be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.