473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Date Formatting

Hi,

I want to display a date in UK format (dd/MM/yyyy) and am using a culture
info object for this. using

Convert.ToString(MyDate, _CultInfo)
works fine, besides that the string includes the time as well.

I have tried using

Convert.ToString(MyDate.ToshortDatestring, _CultInfo)

But this will format the date with US format

Any ideas on how to display a short date formatted string in UK format ?

Niclas
Feb 5 '06 #1
4 1482
Hi Niclas,

I think you want to apply the cultureinfo to the thread to be sure it is
formatted for GB. Try the code below and let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
System.Threading.Thread.CurrentThread.CurrentCultu re = _
New Globalization.CultureInfo("en-GB")
System.Threading.Thread.CurrentThread.CurrentUICul ture = _
New Globalization.CultureInfo("en-GB")
TextBox1.Text = Now.ToShortDateString
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Short date in UK format</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:textbox id="TextBox1" runat="server"></asp:textbox></div>
</form>
</body>
</html>

"Niclas" <li*************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I want to display a date in UK format (dd/MM/yyyy) and am using a culture
info object for this. using

Convert.ToString(MyDate, _CultInfo)
works fine, besides that the string includes the time as well.

I have tried using

Convert.ToString(MyDate.ToshortDatestring, _CultInfo)

But this will format the date with US format

Any ideas on how to display a short date formatted string in UK format ?

Niclas

Feb 5 '06 #2
Niclas,

Use a custom date format string:

Response.Write(String.Format("{0:dd/mm/yyyy}", MyDate)

Here is the MSDN reference for doing custom dates:
http://msdn.microsoft.com/library/de...matstrings.asp

Check out the other standard and custom string.formats (in the left hand
menu) they really come in handy.
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Niclas" <li*************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I want to display a date in UK format (dd/MM/yyyy) and am using a culture
info object for this. using

Convert.ToString(MyDate, _CultInfo)
works fine, besides that the string includes the time as well.

I have tried using

Convert.ToString(MyDate.ToshortDatestring, _CultInfo)

But this will format the date with US format

Any ideas on how to display a short date formatted string in UK format ?

Niclas

Feb 5 '06 #3
Hi Niclas,

Try

date.ToString("dd/MM/yyyy")

HTH

Elton Wang

"Niclas" wrote:
Hi,

I want to display a date in UK format (dd/MM/yyyy) and am using a culture
info object for this. using

Convert.ToString(MyDate, _CultInfo)
works fine, besides that the string includes the time as well.

I have tried using

Convert.ToString(MyDate.ToshortDatestring, _CultInfo)

But this will format the date with US format

Any ideas on how to display a short date formatted string in UK format ?

Niclas

Feb 5 '06 #4
Check out this faq as well:

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=181

Sonu Kapoor [MVP]
---
Posted via www.DotNetSlackers.com
Feb 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ed | last post by:
Hi there, My problem is the following: When I assign a custom formatted Date & Time to a Date variable it loses it’s formatting. Ex. 2005-06-07 15:46 now when I assign this to a variable of...
4
by: Paul | last post by:
Hi, Everything went fine getting a short date format out of SQL into my DataGrid with this: <%# DataBinder.Eval(Container.DataItem, "Created", "{0:d}")%> Then I got too fancy in SQL and...
4
by: dhnriverside | last post by:
Hi peeps I have a datepicker control that's providing dates in the format dd/mm/yyyy (UK). I want to convert this to "yyyy-mm-dd" to store as a text field in my database (had lots of problems...
12
by: Rob T | last post by:
I'm storing a date/time into a SQL table of type datetime. I need it to be precise so the value is stored to the 1000th of a second. ie "insert into myTable mydate values ('08/05/2005...
2
by: johndcal | last post by:
Hello All, I have a date value that I pull from a .csv file. After reading the file and storing the values in an array the value of the date could be found in $array, for example....
2
by: David Veeneman | last post by:
How does one format a date column in a GridView control? I had assumed that the DataFormat string would do it, but MSDN only shows numeric formatting codes. Can dates be formatted using that...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
21
by: Darin | last post by:
I have an applicatoin that works 100% perfect when running on a machine setup for English (United States), but when I change it to Spanish (Mexico), the dates start giving me fits. THe reason is...
7
by: creative1 | last post by:
Hello everyone. I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this. The problem is: I want to print account statement (or any other...
9
by: Martin | last post by:
I'm retrieving some records from a database. One of the fields contains a date/time. I would like to format it as I send it out to the table in the displayed page. Can some one please tell me...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.