Click here to Skip to main content
14,927,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I have a db in which the date structure is in YYYY-MMM-DD(which is default in nature i guess) but when i call in the programe the date is converting to DD-MM-YYYY, i feel what is there in the db it should come as the same. so please can any one help me out

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 25-Jun-13 22:38pm
v2
Comments
OriginalGriff 26-Jun-13 4:38am
   
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

select convert(varchar,getdate(),106)
   
That isn't actually the case, although it may look like it.
SQL (and nearly every other system) does not store a date in any particular format - it is stored as a number of milliseconds since an arbitrary point in time.

It's only when a DateTime item is converted to a string for display that it "acquires" any formatting, and that is specified by the system doing the conversion. If you do not explicitly specify a format when you do the conversion, the localisation settings for that computer will be used by default.

I can't explicitly tell you what to change to get the output you want, because I have no idea at what stage you are doing the conversion, and there could easily be three different computers that could be involved: the SQL server PC, the server your app is running on, and any client PC doing the actual presentation.
   
Example in C#:

theDate.ToString("yyyy-MM-dd")

SQL;
select convert(varchar,getDate(),120)
   
Comments
Vamna 26-Jun-13 5:03am
   
where to write & how to execute it???
Mukesh Ghosh 26-Jun-13 5:07am
   
If you are using C# then write in cs file bellow line
yourDate.ToString("yyyy-MM-dd")

If you are using SQL select then put this in Query
select convert(varchar,getDate(),120)
Refer : Format Date as yyyy-MMM-dd[^]
SQL
declare @d varchar(11)

select @d = CONVERT(varchar(11),current_timestamp,109)

select RIGHT(@d,4) + '-' + LEFT(@d,3) + '-' + right('00'+LTRIM(SUBSTRING(@d,5,2)),2)



--Amit
   
select convert(date,getdate(),120)...

this will convert the present sysdate to YYYYMMDD formate.... in case if u want to get the date which already there in the database u simple use your own datecoloum...

eg: if u given the date coloum as personal_date then the above will be as

select convert(date,personal_date,120)
   
TRY THIS...:)



SQL
select convert(varchar,getDate(),111,112,113......)
   

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