<p>Does anyone know of a way to declare a date constant that is compatible with international dates?</p>

<p>I've tried:</p>

<pre><code>' not international compatible
public const ADate as Date = #12/31/04#

' breaking change if you have an optional parameter that defaults to this value
' because it isnt constant.
public shared readonly ADate As New Date(12, 31, 04)
</code></pre>

[{'answer_id': 57511, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 0, 'selected': False, 'text': '<p>OK, I am unsure what you are trying to do here:</p>\n\n<ul>\n<li>The code you are posting is <strong>NOT</strong> .NET, are you trying to port?</li>\n<li>DateTime\'s cannot be declared as constants.</li>\n<li>DateTime\'s are a data type, so once init\'ed, the format that they were init\'ed from is irrelevant.</li>\n<li>If you need a constant value, then just create a method to always return the same DateTime.</li>\n</ul>\n\n<p>For example:</p>\n\n<pre><code>public static DateTime SadDayForAll()\n{\n    return new DateTime(2001, 09, 11);\n}\n</code></pre>\n\n<h3>Update</h3>\n\n<p>Where the hell are you getting all that from?!</p>\n\n<ul>\n<li>There <strong>are</strong> differences between C# and VB.NET, and this highlights one of them.</li>\n<li><strong>Date</strong> is not a <a href="http://www.ondotnet.com/pub/a/dotnet/2001/07/30/vb7.html" rel="nofollow noreferrer">.NET data type</a> - <strong>DateTime</strong> is.</li>\n<li>It looks like you can create DateTime constants in VB.NET but there are limitations</li>\n<li>The method was there to try and help you, since you cannot create a const from a <strong>variable</strong> (i.e. optional param). That doesn\'t even make sense.</li>\n</ul>\n'}, {'answer_id': 57604, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 3, 'selected': False, 'text': '<p>According to the Microsoft documentation,</p>\n\n<p>"You must enclose a Date literal within number signs (# #). You must specify the date value in the format M/d/yyyy, for example #5/31/1993#. This requirement is independent of your locale and your computer\'s date and time format settings."</p>\n\n<p>Are you saying that this is not correct and the parsing is affected by the current locale?</p>\n\n<p><strong>Edit:</strong> Did you try with a 4-digit year?</p>\n'}, {'answer_id': 57644, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 0, 'selected': False, 'text': '<p>Ok right, I understand more where you are coming from..</p>\n\n<p>How about:</p>\n\n<ul>\n<li>Create a static method that returns the date constant. This overcomes the international issue since it is returned as the specific DateTime value.</li>\n<li>Now I remember optional params from my VB6 days, but can you not just overload the method? If you are using the overloaded method without the date, just pull it from the static?</li>\n</ul>\n\n<p><strong>EDIT:</strong> If you are unsure what I mean and would like a code sample, just comment this post and I will chuck one on.</p>\n'}, {'answer_id': 57695, 'author': 'Michael Haren', 'author_id': 29, 'author_profile': 'https://Stackoverflow.com/users/29', 'pm_score': 1, 'selected': False, 'text': '<p>Once you have data into Date objects in VB, you don\'t have to worry about globalization until you compare something to it or try to export it.</p>\n\n<p>This is fine:</p>\n\n<pre><code>Dim FirstDate as Date = Date.UtcNow() \'or this: = NewDate (2008,09,10)\'\nDim SecondDate as Date\n\nSecondDate = FirstDate.AddDays(1)\n</code></pre>\n\n<p>This pulls in the globalization rules and prints in the current thread\'s culture format:</p>\n\n<pre><code>HeaderLabel.Text = SecondDate.ToString()\n</code></pre>\n\n<p>This is bad: </p>\n\n<pre><code>Dim BadDate as Date = CDate("2/20/2000")\n</code></pre>\n\n<p>Actually--even that is OK if you force CDate in that case to use the right culture (InvariantCulture):</p>\n\n<pre><code>Dim OkButBadPracticeDate as Date = CDate("2/20/2000", CultureInfo.InvariantCulture)\n</code></pre>\n\n<p>If you want to force everything to a particular culture, you need to set the executing thread culture and UI culture to the desired culture (en-US, invariant, etc.).</p>\n\n<p>Make sure you aren\'t doing any work with dates as strings--make sure they are actual Date objects!</p>\n'}, {'answer_id': 59626, 'author': 'Jason DeFontes', 'author_id': 6159, 'author_profile': 'https://Stackoverflow.com/users/6159', 'pm_score': 4, 'selected': True, 'text': '<p>If you look at the IL generated by the statement</p>\n\n<pre><code>public const ADate as Date = #12/31/04#\n</code></pre>\n\n<p>You\'ll see this:</p>\n\n<pre><code>.field public static initonly valuetype [mscorlib]System.DateTime ADate\n.custom instance void [mscorlib]System.Runtime.CompilerServices.DateTimeConstantAttribute::.ctor(int64) = ( 01 00 00 C0 2F CE E2 BC C6 08 00 00 )\n</code></pre>\n\n<p>Notice that the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.datetimeconstantattribute.aspx" rel="noreferrer">DateTimeConstantAttribute</a> is being initialized with a constructor that takes an int64 tick count. Since this tick count is being determined at complile time, it seems unlikely that any localization is coming into play when this value is initialized at runtime. My guess is that the error is with some other date handling in your code, not the const initialization.</p>\n'}]
['https://Stackoverflow.com/questions/57488', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5966/']