473,479 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

datetime query

jed
SELECT (hrs) AS total_hours,(mins)AS total_mins FROM Timerecords WHERE
(workdate between 02/06/2007 and 06/06/2007;

This statement doesn't work because it doesn't have times associated
with the dates.When i store the dates in the database originally it
automatically adds time to them is there anyway i can just enter dates
without the time.Any code examples please! thanks.

Jul 3 '07 #1
3 1661
You should be using a parameterized query for this. You would create
the query string like:

SELECT (hrs) AS total_hours,(mins)AS total_mins FROM Timerecords WHERE
(workdate between @from and @to);

And then you would add two parameters to the SqlCommand you are
generating. You would then set the value of those parameters to the date,
and it will do the rest for you (as well as convert the date to a value that
is not dependent on the locale, which is what you are doing).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<je*@auto-soft.co.zawrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
SELECT (hrs) AS total_hours,(mins)AS total_mins FROM Timerecords WHERE
(workdate between 02/06/2007 and 06/06/2007;

This statement doesn't work because it doesn't have times associated
with the dates.When i store the dates in the database originally it
automatically adds time to them is there anyway i can just enter dates
without the time.Any code examples please! thanks.

Jul 3 '07 #2
jed,
this should be in one of the SQL Server newsgroups, it isn't about the C#
language at all.

DateTime database table columns normally store a complete datetime object
that includes the time. if you only supply a date, then 12:01 AM (or whatever
the database default is) becomes the default time for that column value.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"je*@auto-soft.co.za" wrote:
SELECT (hrs) AS total_hours,(mins)AS total_mins FROM Timerecords WHERE
(workdate between 02/06/2007 and 06/06/2007;

This statement doesn't work because it doesn't have times associated
with the dates.When i store the dates in the database originally it
automatically adds time to them is there anyway i can just enter dates
without the time.Any code examples please! thanks.

Jul 3 '07 #3
jed
On Jul 3, 6:23 am, j...@auto-soft.co.za wrote:
SELECT (hrs) AS total_hours,(mins)AS total_mins FROM Timerecords WHERE
(workdate between 02/06/2007 and 06/06/2007;

This statement doesn't work because it doesn't have times associated
with the dates.When i store the dates in the database originally it
automatically adds time to them is there anyway i can just enter dates
without the time.Any code examples please! thanks.
Thanks all dont worry managed to sort it out

Jul 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2859
by: JTWhaler | last post by:
I'm looking for an efficient t-sql script to loop through all user tables in a db and determine/print the value of each row having a datetime field (including cases where there are multiple...
1
2928
by: Amir | last post by:
Hi all, I have a table called PTRANS with few columns (see create script below). I have created a view on top that this table VwTransaction (See below) I can now run this query without a...
1
2048
by: antao | last post by:
I'm keeping in the database a log of all the sessions for my application. I'm trying to write a stored procedure that returns all the sessions that; the login contains a certain string, loggedin...
0
1306
by: Mark Fannon | last post by:
I created a database in SQL Server 2k which has a datetime field with only time info in it. When I create a parameter query in Access '02 to execute against that database and prompt for Start and...
14
3707
by: ChrisM | last post by:
Could anyone please tell me the difference between these 2 lines: myDate = DateTime.Now; and myDate = DateTime.Parse(DateTime.Now.ToString("dd/MM/yyyy")); Seeing as later on in the...
2
1604
by: rdraider | last post by:
Hi, We have a lame app that uses 2 datetime(8) fields, 1 stores the date, the other the time. example query: select aud_dt, aud_tm from orders results: aud_dt ...
6
3373
by: rn5a | last post by:
I am inserting records in a MS-Access database table. The data type of one of the columns named *OrderDate* in the DB table is Date/Time. This is the SQL query I am using to insert the records in...
3
4047
by: Jassim Rahma | last post by:
Hi, I want to know how can i query from sql server date field without the time? i mean if i have the following dates: 8/22/2007 12:00:00 AM 8/22/2007 12:23:00 AM 8/22/2007 04:15:00 PM and...
5
7617
by: Mike | last post by:
Hi, I use MS SQL Express and VS 2005 c#, win application. I would like to select value rom DateTimePicker and list all values for selected date within GridView. I have method as follows: ...
10
4087
by: SenileOwl | last post by:
I'm working in vb.net. I'm trying to create a query for a table adapter that will filter data. The query is SELECT CommitteeId, CommitteePostion FROM MemberIndexApp WHERE ((UserName = @UserName)...
0
7027
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
7019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6719
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6847
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
5312
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,...
1
4757
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
555
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.