In this output, the date format have changed from what I have inserted in previous step no. 1.The date format actually changed from "dd/MM/yyyy” to “MM/dd/yyyy”. Can anybody please suggest why this happening and how to get the in dd/MM/yyyy format in gridview
column and how to get dd/MM/yyyy format in C#. And lastly i want only Date in "dd/mm/yyyy" eg. 09/01/2013 format without time.
dipakprodhan
Member
7 Points
53 Posts
Problem in Date Formating.
Jan 09, 2013 06:17 PM|LINK
I have problem regarding date format, i have followed under mentioned steps:-
1) I have inserted Todays date:-
--------------------------------------------------
SqlCommand com = new SqlCommand("insert into tbl_test (dt) values ('" + DateTime.Now.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture) +"') ", con);
2) In Sql Server table date column:- (DateType)
-----------------------------------------------------
01-09-2013 00:00:00
3)Gridview
-----------------
<Columns>
<asp:BoundField HeaderText="Date" DataField="dt" DataFormatString="{0:g}" HtmlEncode="false"/>
</Columns>
Or,
<Columns>
<asp:BoundField HeaderText="Date" DataField="dt" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"/>
</Columns>
Asp.Net - Output
------------
01-09-2013
In this output, the date format have changed from what I have inserted in previous step no. 1.The date format actually changed from "dd/MM/yyyy” to “MM/dd/yyyy”. Can anybody please suggest why this happening and how to get the in dd/MM/yyyy format in gridview column and how to get dd/MM/yyyy format in C#. And lastly i want only Date in "dd/mm/yyyy" eg. 09/01/2013 format without time.
Thanks in advance.
Dipak
sen338
Member
498 Points
118 Posts
Re: Problem in Date Formating.
Jan 09, 2013 06:38 PM|LINK
When you getting date from database just convert the date to following format
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]
replace Gatdate() with you dateColumn
dipakprodhan
Member
7 Points
53 Posts
Re: Problem in Date Formating.
Jan 09, 2013 06:50 PM|LINK
Thanks for the reply, but again i am getting similar output.
SELECT CONVERT(VARCHAR(10),dt, 103) AS [DD/MM/YYYY] from dbo.tbl_test;
Output
----------------
01/09/2013 --> Again "mm/dd/yyyy" format.
Thanx
Dipak
sen338
Member
498 Points
118 Posts
Re: Problem in Date Formating.
Jan 09, 2013 07:07 PM|LINK
Check this one
SELECT CONVERT(VARCHAR(10),convert(datetime,dt), 103) AS [DD/MM/YYYY] from dbo.tbl_test;
dipakprodhan
Member
7 Points
53 Posts
Re: Problem in Date Formating.
Jan 10, 2013 04:43 AM|LINK
Thanks for the reply, but again i am getting similar output.
SELECT CONVERT(VARCHAR(10),convert(datetime,dt), 103) AS [DD/MM/YYYY] from dbo.tbl_test;
Output:
DD/MM/YYYY
-----------------------
01/09/2013 --> Again "mm/dd/yyyy" format.
Thanx
Dipak
Sujeet Saste
Contributor
2998 Points
572 Posts
Re: Problem in Date Formating.
Jan 10, 2013 04:51 AM|LINK
Hi Dipak,
Use following in your query, then you you don't need to do any change in your c# code.
Here FromDate is my column name, replace it with your columan name.
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
ManikandanUl...
Participant
850 Points
253 Posts
Re: Problem in Date Formating.
Jan 10, 2013 05:01 AM|LINK
pls refer the below link
http://www.sql-server-helper.com/tips/date-formats.aspx
Click "…Mark As Answer" if my reply helpful....
dipakprodhan
Member
7 Points
53 Posts
Re: Problem in Date Formating.
Jan 10, 2013 05:17 AM|LINK
Thanks for the reply, i am getting different output, but my issue is still there
Actually i was looking for "dd/mm/yyyy" format. eg. 10/01/2013.As in the insert query which i have previously mentioned
was like this.
SqlCommand com = new SqlCommand("insert into tbl_test (dt) values ('" + DateTime.Now.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture) +"') ", con);
In DataBase :
----------------------
01-10-2013 00:00:00
After query-
SELECT REPLACE(CONVERT(varchar(11),(dt),113),' ','/') as dt from dbo.tbl_test;
Output:
dt
-----------------------
01/Sep/2013
But i want "dd/mm/yyyy" format. eg. 10/01/2013 as ouput.
Thanx
Dipak
makwei88
Member
498 Points
115 Posts
Re: Problem in Date Formating.
Jan 10, 2013 05:24 AM|LINK
Sujeet Saste
Contributor
2998 Points
572 Posts
Re: Problem in Date Formating.
Jan 10, 2013 05:41 AM|LINK
Hi, here is your solution, give it try and let me know :
Hope it will work...
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog