473,545 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datetime query

jed
SELECT (hrs) AS total_hours,(mi ns)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 1662
You should be using a parameterized query for this. You would create
the query string like:

SELECT (hrs) AS total_hours,(mi ns)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.co m

<je*@auto-soft.co.zawrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
SELECT (hrs) AS total_hours,(mi ns)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,(mi ns)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,(mi ns)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
2863
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 datetime fields per row) Help greatly appreciated..
1
2933
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 problem: select * from dbo.VwTransaction where
1
2053
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 after a certain datetime and loggedout before another datetime. Any combination of these parameters can be used and, if none, returns all the log. ...
0
1307
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 End time, it returns zero rows no matter what I do. Here is a SQL Server query created with SQL Enterprise Manager, which works.
14
3725
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 code, the ExecuteNonQuery works with the first
2
1610
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 aud_tm
6
3380
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 the Access DB table: =============================== strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total, OrderDate) VALUES (CID, PID,...
3
4048
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 i want to SELECT all the 8/22/2007 dates..
5
7624
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: public DataTable GetOffersForDate_A(DateTime OfferDate) {
10
4094
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) AND (LoginDate = @LoginDate)) The table lies in a SQL Server and the LoginDate's type is DATETIME. Right now, the query is returning nothing. I'm...
0
7479
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7669
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7926
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5987
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4962
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3468
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.