Hi,
I am practising SQL Serverso my question is from the basics. I could not get the right answer from other search engines but i am sure i will be rightly guided here.
date and time are stored in a single field 'gps_date' and each field shows details like this: 2011-02-05 10:21:47.000
I need to filter the date and time field to list:
my very basic sql statement is show below. How can I add the above features to it. -
SELECT * FROM gps_data where gps_device_id = '0123456'
-
I frequently use this to strip off the time part (it gets converted to midnight) - SELECT DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))
so your query would be -
SELECT * FROM gps_data where gps_device_id = '0123456'
-
and
-
DATEADD(D, 0, DATEDIFF(D, 0, gps_date))=DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))
-
likewise for a daterange, -
SELECT * FROM gps_data where gps_device_id = '0123456'
-
and
-
DATEADD(D, 0, DATEDIFF(D, 0, gps_date)) between convert(datetime,'2011-01-21')
-
and convert(datetime, '2011-02-22')
-
Im pretty sure that putting the date into military format you dont need to specify a format code.
The above code pulls out all data between 2011-01-21 and 2011-02-21 (2011-02-22 is the same as the last moment of the 21st Feb)
3 8363
I frequently use this to strip off the time part (it gets converted to midnight) - SELECT DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))
so your query would be -
SELECT * FROM gps_data where gps_device_id = '0123456'
-
and
-
DATEADD(D, 0, DATEDIFF(D, 0, gps_date))=DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))
-
likewise for a daterange, -
SELECT * FROM gps_data where gps_device_id = '0123456'
-
and
-
DATEADD(D, 0, DATEDIFF(D, 0, gps_date)) between convert(datetime,'2011-01-21')
-
and convert(datetime, '2011-02-22')
-
Im pretty sure that putting the date into military format you dont need to specify a format code.
The above code pulls out all data between 2011-01-21 and 2011-02-21 (2011-02-22 is the same as the last moment of the 21st Feb)
Here, read this for additional info...
Good Luck!!!
~~ CK
Thanks for both replies..
great help
Sign in to post your reply or Sign up for a free account.
Similar topics
by: gil |
last post by:
I'm trying to INSERT based on info selected from another table.
How can I concatenate a string of time to the column 'myDate' below (the
value being inserted)?
INSERT INTO c5...
|
by: JP SIngh |
last post by:
Can someone please suggest the correct way to store the date & time in SQL
Server? I want to store the date and time a record was created.
What should the field type be in SQL Server?
How can...
|
by: Javier |
last post by:
I have a field type Date/Time that automatically defaults to Now().
I'm having a problem writing a query that will retrieve all the
records for a specific date the user to enters when prompted. I...
|
by: MLH |
last post by:
I have a database (datatrek.mdb) with a table named DATA.
The table has a date/time field with default
value = Now(). It has 100 records in it entered over a 50-minute
period.
I would like the...
|
by: kaka |
last post by:
I'm runnig Redhat 7.3 with postgresql 7.3.4 builded from sources and
upgraded recently. I receive this error ( never received before upgrade
) and I don' t know what to do.
Error while executing...
|
by: Dixie |
last post by:
How can I programatically, take some Date/Time fields present in a table in
the current database and change their type to text?
dixie
|
by: matturbanowski |
last post by:
Hi,
I have a date/time field in a SQL2000 database, and what I would like
to do is to filter on a specific part of the field, for example the
time or hour.
Supposing I have a set of data for...
|
by: vai |
last post by:
hi all,
i'm developing a stock management system.
in this system i'm developing a billing system which on daily & monthly basis.
i'm using ms-acess database as backend & visual baic as front end....
|
by: Kyote |
last post by:
I have a textbox that is databound to a table in an access database.
The field only contains month/day/year but my databound textbox is
also showing a time. Is there any way to prevent it from...
|
by: dizzydangler |
last post by:
Just a quick question...I'm running an MS Access 2007 db that tracks appointments in a single table. Date and time are entered as separate fields in short date (mm/dd/yyyy) and short time (hh:mm)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |