Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a database as follows;

Date of birth datetime(datatype)

in data base store as 1/9/1986 12:00:00

but i want the format 1-sep-1986.


how to do.pleae help me.
Posted
Comments
[no name] 8-Jan-13 23:37pm    
In DataBase it should be saved in "1/9/1986 12:00:00" this format only.

You can't store it in "1-sep-1986" this format.
But in Front End you can display what type you want.There is no chance to store in Backend

when a column having datatype date...

1 #

In Open mode Table Records view,(table name -> right clicked -> open)
displaying date's format is depends on System Date format.
Note: for testing change system date format and close & reopen sql server and open table again


2 #

but remember always,
when ever
inserting date
updating date
or comparing date in where condition with date column
use format 'yyyy-MM-dd'


3 #

you can Just display date in format you want, it does not effect table data
for display date in different formats while fetching data using sql query select statement, by default display date is 'yyyy-MM-dd'
in select statement you can choose format using sql functions,
example
SQL
select getdate() as [default]
select convert(varchar(10),getdate(),103) as [dd-MM-yyyy]
select convert(varchar(10),getdate(),101) as [MM-dd-yyyy]
select convert(varchar(10),getdate(),102) as [yyyy-MM-dd]

for more date formats...
http://www.sql-server-helper.com/tips/date-formats.aspx
http://msdn.microsoft.com/en-us/library/ms189491.aspx[^]

so, answer of your question is you can not store date in a format you desire<br />
but you can display it in different format


Happy Coding!
:)
 
Share this answer
 
v2
Comments
madhuri@mumbai 9-Jan-13 0:21am    
Good answer aarti... you have given in detail.
Aarti Meswania 9-Jan-13 0:22am    
Thank you! :)
Prasad_Kulkarni 9-Jan-13 0:24am    
5'ed! Good answered!
Aarti Meswania 9-Jan-13 0:25am    
Thank you! :)
ridoy 9-Jan-13 0:36am    
+5
In DataBase it should be saved in "1/9/1986 12:00:00" this format only.
You can't store it in "1-sep-1986" this format.
But in Front End you can display what type you want.There is no chance to store in Backend
 
Share this answer
 
hi dear,

In Backend, the format stored as per pc Date Format on which database is running.

You Can fatch it as your format from database like---
SQL
select Replace(convert(Nvarchar,getdate(),106),' ','-')
 
Share this answer
 
hey refer below query:
SQL
SELECT     REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '-') AS [DD-Mon-YY]

and also refer below links::
sql-server-2008-date-format[^]
 
Share this answer
 
use like this:
C#
DateTime dtDate = Convert.ToDateTime(dataReader["YourDateFieldName"]);
string strFormatedDate = dtDate.ToString("dd-MM-yyyy");
 
Share this answer
 
v2
This gets asked daily. Your database is storing a date. The format is just what you see, when you do a select. It's a default, but the data is data, not formatted. You can display it in the way you want in your presentation layer. It is not in any format, in your DB.
 
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