473,836 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date Time Format Problem

I have a program which need to get the date in the format of dd/MM/yyyy
(example 24/7/2005)

but when I use DateTime.Now(). ToShortDatetime () the date come back as
MM/dd/yyyy (example 7/24/2005)

This cause much problems

I would like to know how to change the .NET regional setting so the
date will come back as dd/MM/yyyy

either by changing the computer settings or by code

Nov 21 '05
10 8467
As Dragon suggests:
| My fault. I passed 'Nothing' as the 3rd argument. Passing InvariantInfo
| works.
If you pass Nothing for the 3rd argument it means to use
CultureInfo.Cur rentCulture.

Which may have its DateTimeFormatI nfo set to expect something other the /
for the date separator (in the case of Europe & Russia verses the US).

I normally use CultureInfo.Inv ariantInfo (which has an invariant
DateTimeFormatI nfo object attached) instead of
DateTimeFormatI nfo.InvariantIn fo. In either case
DateTimeFormatI nfo.InvariantIn fo says to expect / for the date separator.

The "/" in "dd/M/yyyy" says to use the date separator from the
DateTimeFormatI nfo object passed, while the "\/" in "d\/M\/yyyy" says to use
a "/" literally as the date separator.

See DateTimeFormatI nfo.DateSeparat or:


And Custom DateTime Format Strings:


For details.

Hope this helps
"Armin Zingler" <az*******@free net.de> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb
| > Armin,
| > | First I wanted to suggest ParseExact too, but it doesn't work if
| > it's | "24/12/2005", thus the self-written function.
| >
| > Really! which version of the framework?
| >
| > Dim ChristmasEve As DateTime =
| > DateTime.ParseE xact("24/12/2005", "dd/M/yyyy",
| > Globalization.D ateTimeFormatIn fo.InvariantInf o)
| > Debug.WriteLine (ChristmasEve.T oLongDateString ())
| >
| >
| > Returns: Saturday, December 24, 2005 on .NET 1.1 (in the US, in
| > other countries it will Return Dec 24th 2005 in possibly other
| > formats)!
| My fault. I passed 'Nothing' as the 3rd argument. Passing InvariantInfo
| works.
| I don't understand why this makes the difference. Maybe the formats are
| different, i.e. the order of month, day, year or the seperator is
| but why does one allow a single digit only while the other one accepts one
| or two digits? I thought (Parse)exact means (Parse)exact.
| But wait... this also works:
| d = DateTime.ParseE xact("24/10/2005", "d\/M\/yyyy", Nothing)
| d = DateTime.ParseE xact("4/10/2005", "d\/M\/yyyy", Nothing)
| d = DateTime.ParseE xact("24/1/2005", "d\/M\/yyyy", Nothing)
| d = DateTime.ParseE xact("4/1/2005", "d\/M\/yyyy", Nothing)
| Same format string independent from number of digits per day or month. :)
| Armin
Nov 21 '05 #11

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

Similar topics

by: Ian | last post by:
I have a problem I hope someone can point out where I am going wrong. I need to store a date/time in a cookie ( ie the date a visitor last visited ) However the date format changes to US, despite LCID being set to UK. I have googled extensively but can't work it out. This is my code to give write the current date/time to screen: <% Session.LCID = 2057 Response.Write Now() & "<br>" &
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time = '01-SEP-02' I'm getting no results. The date_and_time field is formatted like this: 2002-SEP-02 00:01:04
by: Dario Di Bella | last post by:
Hi all, we have the following urgent issue affecting our development team. Initially we had one particular workstation that failed executing queries on a DB2 database, raising an invalid date format exception (SQLSTATE=22007). The same queries worked fine on all the other workstations. The date format we want to use is "dd/mm/yyyy".After reinstalling several times the db2 runtime client w/ different options, we found on a technical forum...
by: kevin carter | last post by:
hi i have a table conataining several fields one of which is date i want to be able to search the table on the date field using code. the code below generates the query from a form, however i get an error message "Run time Error 2001" when this code is run. Can anyone please tell me where i have gone wrong or how to stop this error message Dim db As DAO.Database Dim qdf As DAO.QueryDef
by: Lyn | last post by:
Hi, I am developing a project in which I am checking for records with overlapping start/end dates. Record dates must not overlap date of birth, date of death, be in the future, and must not overlap existing records from the same table. I had this all working some time ago, but recently when I have gone back to do more testing, part of these validations no longer work. While there have been changes to the code in the meantime, I cannot...
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the current date. If not, I'd like to display the error message to ValidationSummary. It seems to make sense to me to use CompareValidator but the problem is put the current date into CompareValidator. So, I created a hidden text field in my aspx. ...
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract the value in timeonly format by using this command Format(now,"HH:mm:ss") But when I insert it into the Sql Server database, it embadded date value with it. the output looks like that "01/01/1900 08:59:00" in that case time is
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as follows: function doDateCheckNow(source, args) { var oDate = document.getElementById(source.controltovalidate); // dd/mm/yyyy
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, here is my table structure, Name: Table1
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the database I have a table with Date/time column. The database is located on a machine that is set to dd/mm/yyyy also. When I enter date 7/1/08 (as in January 7, 2008), it stores it in the database as 1/7/08 instead of 7/1/08. Why is it like that...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.