473,399 Members | 3,106 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,399 software developers and data experts.

How to get DateTime in required format?

Hello group
I am using the now function to obtain the time, however because
my server is located in a different locale, I am getting the wrong
format - instead of 07/08 etc I am getting 08/07 etc (the American
format). Is there a simple way to change this?
Aug 7 '07 #1
8 3350
On Aug 7, 11:14 am, <Smuggywrote:
Hello group
I am using the now function to obtain the time, however because
my server is located in a different locale, I am getting the wrong
format - instead of 07/08 etc I am getting 08/07 etc (the American
format). Is there a simple way to change this?
to format output you can use the ToString() method with appropriate
formats as follows

DateTime.Today.ToString("dd/MM");

Aug 7 '07 #2
Hi,

Use DateTime.ParseExact("parsing string", iformatprovider) where in format
provider you can specify the culture.
I hope that will be a good start point.

SevDer
www.sevder.com

<Smuggywrote in message news:ek**************@TK2MSFTNGP04.phx.gbl...
Hello group
I am using the now function to obtain the time, however because
my server is located in a different locale, I am getting the wrong
format - instead of 07/08 etc I am getting 08/07 etc (the American
format). Is there a simple way to change this?

Aug 7 '07 #3
Use DateTime.ParseExact("parsing string", iformatprovider) where in format
provider you can specify the culture.
I hope that will be a good start point.
I have

dim a as datetime
a.parseexact(a.today,"en-GB")

is this correct?
>
SevDer
www.sevder.com

Aug 7 '07 #4
On Aug 7, 11:23 am, "SevDer" <sev...@newsgroup.nospamwrote:
Hi,

Use DateTime.ParseExact("parsing string", iformatprovider) where in format
provider you can specify the culture.
I hope that will be a good start point.
He is using the Now function to obtain the time

I am using the now function to obtain the time
Aug 7 '07 #5
On Aug 7, 11:37 am, <Smuggywrote:
Use DateTime.ParseExact("parsing string", iformatprovider) where in format
provider you can specify the culture.
I hope that will be a good start point.

I have

dim a as datetime
a.parseexact(a.today,"en-GB")

is this correct?
DateTime.ParseExact method converts the string to a date. You have
already a date value. All what you need is to show that date in the
format you need. Either use .ToString() method, or change a culture in
your application.

Go to web.config and add this

<globalization culture="en-GB" uiCulture="en-GB" />

Aug 7 '07 #6
<Smuggywrote in message news:uc**************@TK2MSFTNGP04.phx.gbl...
>Use DateTime.ParseExact("parsing string", iformatprovider) where in
format
provider you can specify the culture.
I hope that will be a good start point.

I have

dim a as datetime
a.parseexact(a.today,"en-GB")

is this correct?
DateTime.Now.ToString("dd MMM yyyy"), assuming you want both Y2k
compatability and non-ambiguity...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 7 '07 #7
Go to web.config and add this
>
<globalization culture="en-GB" uiCulture="en-GB" />
Thanks, I did it this way, I found it in the msdn

System.Threading.Thread.CurrentThread.CurrentCultu re = New
System.Globalization.CultureInfo("en-GB", False)

After this the Now function works correctly.

>

Aug 7 '07 #8
On Aug 7, 12:06 pm, <Smuggywrote:
Go to web.config and add this
<globalization culture="en-GB" uiCulture="en-GB" />

Thanks, I did it this way, I found it in the msdn

System.Threading.Thread.CurrentThread.CurrentCultu re = New
System.Globalization.CultureInfo("en-GB", False)

After this the Now function works correctly.
It will work, but you always have to set the culture for the current
thread. If your application is designed for UK only, you can specify
that value on the global level in the web.config file. You also can
use the @Page Directive

<%@Page Culture="en-GB" ....

Hope this helps

Aug 7 '07 #9

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...
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
1
by: adolf garlic | last post by:
I'm having a problem with dates. (No not the sort that you have at christmas) I have a webform with a text box and a calendar control. You can either - enter a date manually (we are talking uk...
1
by: Charlie Brown | last post by:
I would like to make my datagrid show a blank text field for datetime values that are DBNULL. Does any know how to format that way?
5
by: John B | last post by:
Hi all, Any idea why this code results in a FormatException? DateTime.ParseExact("40708", "dMMyy", CultureInfo.CurrentCulture) If I use "040708" with the same format string it works and it...
3
by: raulbolanos | last post by:
Hello guys, I get this time from DateTime.Now "6/12/2009 11:45:28 AM" and I need to convert it ISO 8601 which is the one that SQL accepts "2009-12-06 11:45:28". What can I do?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.