Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i woul like to save date in dd-mm-yyyy format but problem is that

SQL
CREATE TABLE DATELOG (DATE DATETIME,NAME VARCHAR(20))
--this is in mm-dd-yyyy formate save
INSERT INTO DATELOG VALUES(CONVERT(datetime,'2/1/84'),'XXX')
--this is in dd-mm-yyyy format not save
INSERT INTO DATELOG VALUES(CONVERT(datetime,'22/1/84'),'XXX')

SELECT * FROM DATELOG
SELECT REPLACE(CONVERT(VARCHAR(13),DATE,105),'-','/') AS DATE FROM DATELOG

----------------------------------------------------------------------------


if possible then send me querry

thanx in advance
Posted

Well, if you want a specific format while saving the data in database, then change the language setting of your DB to desired format of date.

You cannot force it while inserting as long as the datatype is DateTime and the system is applying a defined format to it.

Though, generally this is not required. Your concern should be with data while retrieving or showing in presentation layer. That time, you can specify a particular format to display.
 
Share this answer
 
Do not save dates/times as strings, it just causes problems; that is why the DATETIME type exists. The only time you ever need the date in any format (dd/mm/yy, yy/mm/dd, mm/dd/yy etc.) is when you display it on an output device (screen, printer etc). If it is already stored as a string then you lose all flexibility for displaying it in alternate formats, time zones etc.
 
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