473,396 Members | 1,772 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,396 software developers and data experts.

DateTime in WHERE clause

I want to dynamically construct a TSQL with a datetime column in the WHERE
clause. How do I include the millisecond in the query?
"WHERE datetimecolumn = " + dt.ToString() will not include the millisecond.
Thanks.

Jul 28 '08 #1
2 3007
Roy,

You don't want to do it like this. Instead, when creating your
SqlCommand instance, use a parameterized query. Your where clause will look
like this:

WHERE datetimecolumn = @datetimevalue

And then you will add the @datetimevalue parameter through the
parameters collection on the command (passing the value you are looking to
insert for that parameter as well).

The provider will do the conversion for you.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy" <Ro*@discussions.microsoft.comwrote in message
news:8E**********************************@microsof t.com...
>I want to dynamically construct a TSQL with a datetime column in the WHERE
clause. How do I include the millisecond in the query?
"WHERE datetimecolumn = " + dt.ToString() will not include the
millisecond.
Thanks.

Jul 28 '08 #2
On Jul 28, 12:27*pm, Roy <R...@discussions.microsoft.comwrote:
I want to dynamically construct a TSQL with a datetime column in the WHERE
clause. How do I include the millisecond in the query?
"WHERE datetimecolumn = " + dt.ToString() will not include the millisecond.
Thanks.
Hi,

There are two options:
1- Use "WHERE myDate='"+ DateTime.Today.ToShortDateTime() + "'";

or better yet, use a parameter.
Jul 29 '08 #3

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

Similar topics

3
by: KathyB | last post by:
I'm trying to concatenate fields in SQL stored proc for use in text field in asp.net dropdownlist. I'm running into a problem when I try to use a DateTime field, but can't find the answer (so far)...
4
by: Malcolm Diaz | last post by:
Hello all Thank you all in advance. I am completely at a loss here with this error. I am developing a simple interface that will allow a user to enter,execute and view results from a SQL statement...
1
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
by: colinhumber | last post by:
I have a datetime variable coming from my ASP.NET application that has a time portion. I give my users the option to perform an equals, greater than, less than, or between comparison. The trouble...
1
by: virendra.chandra | last post by:
hi guys, this is virendra. I am in big trouble to handle date situation using where clause. i am using ormapper. if the sqlserver and application server has different date format(different...
0
by: RSH | last post by:
I am having a bit of trouble filling a datatable with a query. I'm getting the error message: System.FormatException: String was not recognized as a valid DateTime. at...
2
by: Tina | last post by:
I'm selecting some columns using a .net dataadapter using Select myDate from myTable. then I... DIM dt as new datatable myda.fill(dt) Now in dubugging I am examining the dt.rows(0).ItemArray...
8
by: =?Utf-8?B?Um95?= | last post by:
I need to compare a datetime value against the value in a datetime column in the WHERE clause as accurate as ticks (100 ns). When I construct a query by string.Format("WHERE MyDatetimeColumn =...
4
by: =?Utf-8?B?Um95?= | last post by:
I have a DataRow dr retrieved from a database. One of the column is datetime type. How do I convert it to DateTime structure in .NET? DateTime dt = DateTime.Parse(dr.ToString()) will drop the...
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: 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...
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
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...
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
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
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.