473,378 Members | 1,078 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,378 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 3132
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 ...
1
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
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...
0
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,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.