Click here to Skip to main content
16,018,158 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have data saved in database according to spcific dates now i want to retrive the data of last year/ month but the problem is my date column is of type varchar so how to retrive the data
Posted

There is very unfortunate. In the first place, a date should be of date type and not any other type. Having said that, check this out: SQL Server Functions that helps to convert date and time values to and from string literals and other date and time formats.[^]
 
Share this answer
 
Simple: don't store date time values as strings - it always gives problems.
The trouble is that when users enter dates, they enter them in their local date format:
01-02-12

which could be 1st Feb 2012, 2nd Jan 2012, 12th Feb 2001, or even just plain wrong!
The only time you have any idea what format the user is entering dates in is when he enters them - so if you don't do any validation and conversion at that time then you have completely lost the opportunity and once it enters your DB you have no idea which of them it is.

So change your DB: store date / time values as DATETIME columns, validate and correct your existing data, and work from there. Otherwise, you are always going to get problems and this is just the start of them!
 
Share this answer
 
actually i have saved the data with field bla bla and date with datatype varchar and now i want to access the database on the basis of date ...
but i don t know how??
 
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