Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datetime problem 1

Status
Not open for further replies.

jeanpaul

Technical User
Aug 13, 2000
20
0
0
SE
I would like to search for dates in column with a datetime-type. I use this line;

$result= mssql_query("SELECT * FROM LOG WHERE $find LIKE '%" . $indata . "%' ORDER BY $sort",$con);

1. How do I search for 2001-05-14? It just returns results when I search for 2001. Another thing which may cause the problem is that it displays the results in 14th of May 2001 and so on. In the fields you find 2001-05-14 16:32:01 just like I inserted it. How do I display that without the original, "long" description?

Thanks / Henrik
 
Hello Jeanpaul,

First to display a datetime first convert it to a varchar and then convert it to a special format. For instance
CONVERT(varchar(15), fieldname, 105) returns a format of DD-MM-YYYY.

Secondly when you search on dates there are 2 things to remember:
1st : Dates are in US format that means your query date must be of US format too. This means(MM-DD-YYYY). If you use this format it will work.
2nd : Furthermore when you check for a date and the search date must be included you will have to add 1 day to the searchdate otherwise it will find everything but the until date.


Hope this helps

JNC73

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top