简体   繁体   中英

date search in visual studio 2008 sql express

In my database, dates are displayed in dd/mm/yyyy format, like 08/01/2015 , but when I try to query data according to a date I get no results.

More specifically, I do get results when I query a date value of the form 08/jan/2015 ; it's when I query a date of the form 08/01/2015 that I get nothing. How can I fix this?

Edit: The datatype of the columns involved is variously Datetime or timestamp .

There is lots of thing you can do .....

  1. You can change your SQL server date format.
  2. You can convert your date while getting from Datebase.
  3. You can convert your date while inserting into Datebase.

You can do first option something like this

  SET DATEFORMAT dmy; /*you can set format by this dmy `DD-MM-YYYY` */
  dbcc useroptions    /* you can see changes */

you can do second option something like this

/ For dd/mm/yyyy format /

  SELECT CONVERT(VARCHAR(10),@DateTime ,103) AS Date

you can do third option by doing this

INSERT INTO TableName (DateColumn) VALUES (CONVERT(date, '13-02-2014', 105)
/* above is sample query you can modify it according to your need */

References:

SQL Server Date Format Change after installation of SQL Server

MSDN SET DATEFORMAT

SQL Server CONVERT() Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM