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

dd/mm/yyyy

GM
i have datacolumn that formating dd/mm/yyyy hh/mm/ss. i try getting between from two date like
select * from X Where Date between 01.11.2008 11/12/33 and 30.11.2008 11/12/33. but it runs wrong.i can not displaY DIFFRENCE DATE
Nov 7 '08 #1
3 3131
Use ISO dates

between 2008-11-01 and 2008-11-30
Nov 7 '08 #2
To expand on Pete's answer: The format of the date you are searching on does
not match what the server is using.

A better fix for this is to use parameters in your SQL statement and pass an
actual DateTime control.

For example: Say your SQL statement looked like this:

string sqlStr = "SELECT * FROM X WHERE Date BETWEEN @Date1 AND @Date2";

(if the SQL doesn't work, I apologize)

using (SqlDataAdapter da = new SqlDataAdapter(sqlStr, m_sqlConnectionStr))
{
da.Parameters.Add("@Date1", DateTime).Value = m_objDate1;
da.Parameters.Add("@Date2", DateTime).Value = m_objDate1.AddDays(30);
DataTable table = new DataTable();
try {
da.Fill(table);
} catch (SqlException err) {
#if DEBUG
MessageBox.Show(err.ToString());
#else
Console.WriteLine(err.ToString());
#endif
}
if (0 < table.Rows.Count) {
foreach (DataRow r in table.Rows) {
// do something with your row "r"
}
}
}

"GM" wrote:
i have datacolumn that formating dd/mm/yyyy hh/mm/ss. i try getting between from two date like
select * from X Where Date between 01.11.2008 11/12/33 and 30.11.2008 11/12/33. but it runs wrong.i can not displaY DIFFRENCE DATE
Nov 7 '08 #3
GM wrote:
i have datacolumn that formating dd/mm/yyyy hh/mm/ss. i try getting between from two date like
select * from X Where Date between 01.11.2008 11/12/33 and 30.11.2008 11/12/33. but it runs wrong.i can not displaY DIFFRENCE DATE
Are you storing the values as varchar in the database? A datetime value
doesn's have a format at all, it only gets a format when you format the
value into a string.

If you store the values as varchar, they are not in a format that is
comparable. The only comparable date format is the ISO 8601 format, i.e.
yyyy-mm-dd hh:mm:ss, as the components are always the same length, and
it places the most significant components first in the string. To
compare dates in any other format, you have to convert each value into a
datetime value before doing the comparison, which gets rather slow.

If you store the values as datetime, and see them formatted like you
described in a program that manages the database, e.g. Management
Studio, that only means that the program displays the dates that way,
not that the database itself will understand that date format. The best
way to send DateTime values to the database is to use parameters, as
jp2msft described.

--
Göran Andersson
_____
http://www.guffa.com
Nov 7 '08 #4

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

Similar topics

3
by: Alistair | last post by:
it's the idiot with his query strings again...."yippeee" I hear aaron shout this time the problem is with a date format query I have a query string thus strSQL = "SELECT * FROM users where...
3
by: Ted Johnson | last post by:
The following query works fine against SQL Server 2000 here in the US: SELECT * from TNEWSARTICLES where CreatedOn < '2003-04-25 14:22' But in the UK, it returns this error: 80040e07: The...
6
by: dyw55a | last post by:
How to implement mm/dd/yyyy format for textbox? I have text box with format mm/dd/yyyy. Now I want the cursor i generated whenever user highlight this textbox and whatever user inpu replace one...
2
by: Ange T | last post by:
Hi there, I've read stacks of articles on this subject in this newsgroup, so forgive me that this is just another one. I've tried almost all the suggestions offered, and am still having no luck....
13
by: Roy | last post by:
Hi all, I'm creating a project that should always use this date format when displays the dates or create dates. The back end database is a SQL Server and I like to know what is the logical way...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
12
by: Vincent Delporte | last post by:
Hello My site is hosted on a server in the US, hence set up to use the mm/dd/yyyy date format instead of the European dd/mm/yyyy. Also, MySQL stores dates as yyyy-mm-dd, so I need to convert...
3
by: Eric Layman | last post by:
Hi, In general, how do u configure/script to allow .net to accept date in dd/mm/yyyy format? By default, my sys only allows mm/dd/yyyy format. Eg: Take alook at
4
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.