1> when i will store date in dd-mm-yyyy format but it will bydefault store in MM-dd-yyyy format so how to change the format
2> and when i will fetch date from database how to convert date format
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kunal VaishyaPosted Apr 28, 2012, 5:42 AM
DateTime Dt = DateTIme.Now() // Or DataBase Value
Dt.ToString("dd-MM-yyyy")
Kunal VaishyaPosted Apr 28, 2012, 5:40 AM
Like Employee Table
Id Numeric
Name Varchar(20)
DOB DateTime
Like This
Select Id, Name, select convert(varchar, DOB, 105) As DateOfBirth From Employee
Nilesh MakwanaPosted Apr 28, 2012, 5:31 AM
Kunal VaishyaPosted Apr 28, 2012, 5:16 AM
Sql Inbuild Date Time Formate is MM-dd-yyyy if you store date in dd-MM-yyyy format then check data is proper or not may be .
Sql Formate IS MM-dd-yyyy When you store 12-12-2012 It will not give you error but is wrong thats mean if you ar passing date like this date-Month-year it wring in case of 13-12-2012 it will give you error so try to do this type of testing to beter undastanding
give me code i'll help you
Nilesh MakwanaPosted Apr 28, 2012, 4:51 AM
NIlesh PatelPosted Apr 28, 2012, 4:35 AM
It Is No need to Change Format In SqlServer. When You Retrive Data From Database Use
'select convert( varchar(50),getdate(),103)' This type of Syntax To get date in 'dd-mm-yyyy' Format .and It is Better way to store date in sql in MM-dd-yyyy format at saved record.
Kunal VaishyaPosted Apr 28, 2012, 4:34 AM
In Sql we cant change data in DateTIme Field its own formate
When you fech data you can use like this
USA mm/dd/yy
select convert(varchar, getdate(), 1)
ANSI yy.mm.dd
select convert(varchar, getdate(), 2)
British/French dd/mm/yy
select convert(varchar, getdate(), 3)
German dd.mm.yy
select convert(varchar, getdate(), 4)
Italian dd-mm-yy
select convert(varchar, getdate(), 5)
dd mon yy
select convert(varchar, getdate(), 6)
Mon dd, yy
select convert(varchar, getdate(), 7)
USA mm-dd-yy
select convert(varchar, getdate(), 10)
JAPAN yy/mm/dd
select convert(varchar, getdate(), 11)
ISO yymmdd
select convert(varchar, getdate(), 12)
mon dd yyyy hh:miAM (or PM)
select convert(varchar, getdate(), 100)
mm/dd/yyyy
select convert(varchar, getdate(), 101)
yyyy.mm.dd
select convert(varchar, getdate(), 102)
dd/mm/yyyy
select convert(varchar, getdate(), 103)
dd.mm.yyyy
select convert(varchar, getdate(), 104)
dd-mm-yyyy
select convert(varchar, getdate(), 105)
dd mon yyyy
select convert(varchar, getdate(), 106)
Mon dd, yyyy
select convert(varchar, getdate(), 107)
hh:mm:ss
select convert(varchar, getdate(), 108)
Default + milliseconds mon dd yyyy hh:mi:ss:mmmAM (or PM)
select convert(varchar, getdate(), 109)
mm-dd-yyyy
select convert(varchar, getdate(), 110)
yyyy/mm/dd
select convert(varchar, getdate(), 111)
yyyymmdd
select convert(varchar, getdate(), 112)
Europe default + milliseconds dd mon yyyy hh:mm:ss:mmm(24h)
select convert(varchar, getdate(), 113) or select convert(varchar, getdate(), 13)
hh:mi:ss:mmm(24h)
select convert(varchar, getdate(), 114)