473,386 Members | 1,610 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,386 software developers and data experts.

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 8230
"theinvisibleGhost" <th***************@yahoo.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.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.CurrentCulture 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.Globalization;
.....
CultureInfo ci = CultureInfo.CurrentCulture;
Console.WriteLine(ci.DateTimeFormat.ShortDatePatte rn);

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

Sep 3 '07 #2
Hello theinvisibleGhost,

Detect the culture first, and that use DateTimeFormatInfo 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.comwrote:
Hello theinvisibleGhost,

Detect the culture first, and that use DateTimeFormatInfo class to get the
time formathttp://msdn2.microsoft.com/en-us/library/system.globalization.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("kernel32.dll")]
private static extern uint GetUserDefaultLCID();
[DllImport("kernel32.dll")]
static extern bool SetLocaleInfo(uint Locale, uint LCType,
string lpLCData);
public const int LOCALE_SSHORTDATE = 0x1F;
public const int LOCALE_SDATE = 0x1D;

/// <summary>
/// Sets the short date.
/// </summary>
/// <param name="strShortDate">The STR short date.</param>
public static void SetShortDate(string strShortDate)
{
uint lngLCID;
lngLCID = GetUserDefaultLCID();
SetLocaleInfo(lngLCID, LOCALE_SSHORTDATE, strShortDate);
SetLocaleInfo(lngLCID, 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
"theinvisibleGhost" <th***************@yahoo.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.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...@gmail.comwrote:
"theinvisibleGhost" <theinvisibleGh...@yahoo.comwrote in message

news:11**********************@o80g2000hse.googlegr oups.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
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...
2
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...
7
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...
7
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...
40
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...
6
by: ABC | last post by:
Is there any function return the short date format on the regional and Language Options under control panel?
2
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...
4
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...
3
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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,...

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.