Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a table with field InvoiceDate but its Datatype is in Varchar
I want to select a particular Time Period but it shows all the date apart from my selected Range
Posted
Updated 10-Mar-13 18:31pm
v2
Comments
Garth J Lancaster 11-Mar-13 0:34am    
Why dont you post the relevant code/SQL statement - thats the easisest way for someone to be able to help you - otherwiese we can only guess what you are trying to do
gvprabu 11-Mar-13 0:47am    
Hi,
If you have any chance to change the Data type VARCHAR to DATETIME. Tel me one thing how you are validating the Stored Data is proper DATETIME?
Ankur\m/ 11-Mar-13 1:16am    
You have probably written a wrong query. Post your query here (Use 'Improve Question' widget to update your question) and we might help.
Aarti Meswania 11-Mar-13 1:16am    
InvoiceDate column is varchar but in which format you have stored date?
e.g. dd-MM-yyyy hh:mm:ss tt
or yyyy-MM-dd...
or MM-dd-yyyy...

SQL
select convert(DATETIME, InvoiceDate , 103),* from Invoice 
where  convert(DATETIME, InvoiceDate , 103) between '2013-01-01' and '2013-1-30'
 
Share this answer
 
Hi,
You can also make use of substring.
The Substring function in SQL is used to grab a portion of the stored data

SELECT SUBSTRING(InvoiceDate, startingPosition, Endposition) FROM TableName
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900