473,587 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine/Set Current User Short Date Format

Is there a method of determining which format the short date format is
stored in for the current user on the machine using .NET?

If it is not in UK format I ideally need to be able to set it to UK
format as well.

I'm building an installation tool, and the software which I am
installing will
only work if the regional settings are correct.

Cheers
Chris.

Sep 3 '07 #1
6 8238
"theinvisibleGh ost" <th************ ***@yahoo.comwr ote in message
news:11******** **************@ o80g2000hse.goo glegroups.com.. .
Is there a method of determining which format the short date format is
stored in for the current user on the machine using .NET?
Hello Chris,

You can make use of the CultureInfo.Cur rentCulture object for regional
setting checks. The following code excerpt will output the short date format
for the current user (dd/MM/yyyy for en-GB):

using System.Globaliz ation;
.....
CultureInfo ci = CultureInfo.Cur rentCulture;
Console.WriteLi ne(ci.DateTimeF ormat.ShortDate Pattern);

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info | www.aeroxp.org

Sep 3 '07 #2
Hello theinvisibleGho st,

Detect the culture first, and that use DateTimeFormatI nfo class to get the
time format
http://msdn2.microsoft.com/en-us/lib...fo(VS.71).aspx

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
tIs there a method of determining which format the short date format
tis stored in for the current user on the machine using .NET?
t>
Sep 3 '07 #3
On 3 Sep, 11:28, Michael Nemtsev, MVP <nemt...@msn.co mwrote:
Hello theinvisibleGho st,

Detect the culture first, and that use DateTimeFormatI nfo class to get the
time formathttp://msdn2.microsoft .com/en-us/library/system.globaliz ation.datetim.. .

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog:http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

tIs there a method of determining which format the short date format
tis stored in for the current user on the machine using .NET?
t>
Cheers, I've got it to determine the date format, which is a great
start.
If anyone has any ideas, how I can set the format to be this way
I'd be quite interested!

Thanks
Chris

Sep 3 '07 #4
OK I found a way of doing this using the Windows API
Code Sample:
_______________ _______________ _____________
[DllImport("kern el32.dll")]
private static extern uint GetUserDefaultL CID();
[DllImport("kern el32.dll")]
static extern bool SetLocaleInfo(u int Locale, uint LCType,
string lpLCData);
public const int LOCALE_SSHORTDA TE = 0x1F;
public const int LOCALE_SDATE = 0x1D;

/// <summary>
/// Sets the short date.
/// </summary>
/// <param name="strShortD ate">The STR short date.</param>
public static void SetShortDate(st ring strShortDate)
{
uint lngLCID;
lngLCID = GetUserDefaultL CID();
SetLocaleInfo(l ngLCID, LOCALE_SSHORTDA TE, strShortDate);
SetLocaleInfo(l ngLCID, LOCALE_SDATE, "/");
}

SetShortDate ("dd/MMM/yyyy");
_______________ _______________ _______
I adapted this from this thread here
http://www.codeguru.com/forum/showthread.php?t=16807
Sep 3 '07 #5
"theinvisibleGh ost" <th************ ***@yahoo.comwr ote in message
news:11******** **************@ o80g2000hse.goo glegroups.com.. .
Is there a method of determining which format the short date format is
stored in for the current user on the machine using .NET?

If it is not in UK format I ideally need to be able to set it to UK
format as well.

I'm building an installation tool, and the software which I am
installing will
only work if the regional settings are correct.

Your software actually requires a rigid format for dates? You force someone
in the US that is using your software to set their date format to something
unfamiliar to them?

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Sep 3 '07 #6
On Sep 3, 11:15 pm, "Doug Semler" <dougsem...@gma il.comwrote:
"theinvisibleGh ost" <theinvisibleGh ...@yahoo.comwr ote in message

news:11******** **************@ o80g2000hse.goo glegroups.com.. .
Is there a method of determining which format the short date format is
stored in for the current user on the machine using .NET?
If it is not in UK format I ideally need to be able to set it to UK
format as well.
I'm building an installation tool, and the software which I am
installing will
only work if the regional settings are correct.

Your software actually requires a rigid format for dates? You force someone
in the US that is using your software to set their date format to something
unfamiliar to them?

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?
The software actually comes from the US.
It's a client server system. The server has a setting to either be
in US or UK mode. Which ever it is the clients must be set
to be the same. Not ideal, but it works.
The clients are only ever and due to certain medical
legal requirements will ever be in the same country
as the server. I think it's got to a point where if it aint
broke it won't be fixed!

Sep 7 '07 #7

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

Similar topics

1
4835
by: Laurence Neville | last post by:
This is regarding a change in the Short Date format under Hebrew Regional Settings, that has caused huge problems in our ASP web application. The change appears to have been introduced sometime before Windows 2000 Service Pack 4 and has remained through to Windows XP. I am looking for a solution that doesn't involve rewriting our application (much) and that allows all our users to keep using Hebrew Regional Settings. To summarize our...
2
3643
by: Mary | last post by:
I am trying to develop a query which will determine the average costs using a rolling average of the past 12 months of data. In other words, if I entered the Ship Month of January and the Ship Year of 2004, I would want that month plus the preceding 11 months of data to determine an average cost. How can that criteria be entered in a query so that each month I can get the most current 12 months of data to determine the average costs? ...
7
8473
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from the Toolbox and then set the Format property appropriately. I have noticed that sometimes the Time format will reset spontaneously to Short Date. I looked at the .rc file and found that the usual form for a Short Date is as follows: CONTROL ...
7
31806
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. ...
40
2945
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the front end open at the first form) and even though this links to the back-end files, there are no ldb files created. This is so I know when it is safe to compact the back-end files without going round to make sure everyone is logged off. User...
6
2376
by: ABC | last post by:
Is there any function return the short date format on the regional and Language Options under control panel?
2
6995
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i don´t need the time data i would like to convert all the general date data into short date format, so i would like to delete the time part of the data, it is any way i can do that ???? Thank you in advance and sorry for my english carlos
4
5194
by: john | last post by:
I have an unbound field in which I would like to show january 1 of the current year like this 01-01-2007. I tried this code but it doesn't work: =dateserial(Year(date()),1,1) Can someone help me out? Thanks in advance, john
3
2222
by: Matt Brown - identify | last post by:
Hello, I'm trying to figure out a method to look up by a range of dates, entries in a database. The format of the date in the database is "M\D \yyyy HH:MM:SS". What i need to do is take the dates that are in the database (formatted as above), isolate the date (which is in short format) and compare it to the short formatted date in a datetimepicker.
0
7924
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8219
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, 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...
0
8349
jinu1996
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...
1
7978
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,...
0
6629
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, 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...
0
5395
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();...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1192
bsmnconsultancy
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.