current date query
-
SELECT Dat FROM dbo.tblkmreading WHERE DAT = GETDATE() i have records pertaining to current date , the above query is not fetching the records.Please rectify it
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
-
SELECT Dat FROM dbo.tblkmreading WHERE DAT = GETDATE() i have records pertaining to current date , the above query is not fetching the records.Please rectify it
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
-
Thie GETDATE() Function returns the time now ie: 3/30/2008 12.35.05... You will need to parse the GETDATE() result to return just MM/DD/YYYY and use his in your WHERE clause.
I don't speak Idiot - please talk slowly and clearly
select dat from tblkmreading where dat = convert(varchar(10) , getdate() , 103) still getting the following error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. dat is a datetime type this is the another way i did , but no record is comming select dat from tblkmreading where dat = convert(datetime , getdate() , 103)
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
-
SELECT Dat FROM dbo.tblkmreading WHERE DAT = GETDATE() i have records pertaining to current date , the above query is not fetching the records.Please rectify it
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
Try this declare @Now datetime select @Now = convert(varchar,getdate(),103) SELECT Dat FROM dbo.tblkmreading WHERE DAT >= @Now I suspect your Dat column contains a time as well as a date. The above code trims off the time from getdate.
Bob Ashfield Consultants Ltd
-
Try this declare @Now datetime select @Now = convert(varchar,getdate(),103) SELECT Dat FROM dbo.tblkmreading WHERE DAT >= @Now I suspect your Dat column contains a time as well as a date. The above code trims off the time from getdate.
Bob Ashfield Consultants Ltd
dat is of datetime type still occuring the error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
-
select dat from tblkmreading where dat = convert(varchar(10) , getdate() , 103) still getting the following error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. dat is a datetime type this is the another way i did , but no record is comming select dat from tblkmreading where dat = convert(datetime , getdate() , 103)
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
Is the data stored as DateTime dataType in the database? You cant expect that your query will run at the exact time that a record is written. In this case you may have to change your Where clause to BETWEEN and look from 12:00:00am to 11:59:00pm. Or Between 3/31/2002 12:00:00 And 4/1/2008 12:00:00 Sorry, I dont have a query editor handy to check this out :( DECLARE @Start DateTime SET @Start = '3/31/2008' DECLARE @End DateTime SET @End = '4/1/2008' SELECT [Date] FROM TestData Where [Date] Between @Start and @End
I don't speak Idiot - please talk slowly and clearly
-
dat is of datetime type still occuring the error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
-
What version of SQL Server are you using? My code works fine with 2000 and 2005.
Bob Ashfield Consultants Ltd
If Dat is date time format in your table then use following query SELECT Dat FROM dbo.tblkmreading WHERE convert(varchar,Dat,103) = convert(varchar,GETDATE(),103) If Dat is varchar in your table then use following query SELECT Dat FROM dbo.tblkmreading WHERE convert(varchar,convert(datetime,Dat),103) = convert(varchar,GETDATE(),103)
smile :-)