Hi all,
I am using .NET 2
I have to work with short dates, e.g. 23 April 2008 will come to me as
23/04/08
I am splitting this value into int to put into a DateTime type...
DateTime MyDate = new DateTime(8, 4, 23);
However, when returned, it is returning as 23/04/0008 (obviously incorrect,
but the MyDate.WeekdayName is returning the correct week day name).
Later in my code, I have to do a select on a SQL based on the Date, and
23/04/2008 does not match 23/04/0008
Now, I can pass in the string direct (23/04/08) into my SQL and that will
work, however, I want to be ABSOLUTELY certain that say for example, 11 May
08 won't be interpreted as 5 Nov 08 which is why I am handling it by
splitting my incoming date string.
Any ideas on how I can get it to work the way I want?
--
Best regards,
Dave Colliver. http://www.AshfieldFOCUS.com
~~ http://www.FOCUSPortals.com - Local franchises available 3 990
this might help:
//for date in english:
using System.Globalization;
CultureInfo dateSystem = new CultureInfo( "en-US" );
DateTime mydate = Convert.ToDateTime(this.txtDate.Text,dateSystem);
now mydate wich is from txtDate entered as :mm/dd/yy is good for SQL
also, in some point you may need to check the date before you pass it to
SQL:
String.Format("{0}/{1}/{2}", mydate.Month, mydate.Day, mydate.Year);
Vaf
"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:e6**************@TK2MSFTNGP02.phx.gbl...
Hi all,
I am using .NET 2
I have to work with short dates, e.g. 23 April 2008 will come to me as
23/04/08
I am splitting this value into int to put into a DateTime type...
DateTime MyDate = new DateTime(8, 4, 23);
However, when returned, it is returning as 23/04/0008 (obviously
incorrect, but the MyDate.WeekdayName is returning the correct week day
name).
Later in my code, I have to do a select on a SQL based on the Date, and
23/04/2008 does not match 23/04/0008
Now, I can pass in the string direct (23/04/08) into my SQL and that will
work, however, I want to be ABSOLUTELY certain that say for example, 11
May 08 won't be interpreted as 5 Nov 08 which is why I am handling it by
splitting my incoming date string.
Any ideas on how I can get it to work the way I want?
--
Best regards,
Dave Colliver. http://www.AshfieldFOCUS.com
~~ http://www.FOCUSPortals.com - Local franchises available
David brought next idea :
Hi all,
I am using .NET 2
I have to work with short dates, e.g. 23 April 2008 will come to me as
23/04/08
I am splitting this value into int to put into a DateTime type...
DateTime MyDate = new DateTime(8, 4, 23);
Here you are specifying the year 8, instead of 2008. You have to handle
the conversion to "2008" (maybe by adding 2000, but what if you got
"99" meaning "1999"?)
>
However, when returned, it is returning as 23/04/0008 (obviously incorrect,
but the MyDate.WeekdayName is returning the correct week day name).
That may break for some other date.
Later in my code, I have to do a select on a SQL based on the Date, and
23/04/2008 does not match 23/04/0008
Now, I can pass in the string direct (23/04/08) into my SQL and that will
work,
SqlServer interprets two-digit years below 50 (I think) as 20xx and
higher values as 19xx. And it will break on years before 1752 or
thereabouts.
however, I want to be ABSOLUTELY certain that say for example, 11 May
08 won't be interpreted as 5 Nov 08 which is why I am handling it by
splitting my incoming date string.
Any ideas on how I can get it to work the way I want?
Do not pass the date as a string. Use a Parameter to pass the value to
sql and use the (correct) DateTime value directly as the parameter
value.
Hans Kesting
Hi,
Thanks for responding...
Inline...
"Hans Kesting" <in************@spamgourmet.comwrote in message
news:mn***********************@spamgourmet.com...
David brought next idea :
>Hi all,
I am using .NET 2
I have to work with short dates, e.g. 23 April 2008 will come to me as 23/04/08
I am splitting this value into int to put into a DateTime type...
DateTime MyDate = new DateTime(8, 4, 23);
Here you are specifying the year 8, instead of 2008. You have to handle
the conversion to "2008" (maybe by adding 2000, but what if you got "99"
meaning "1999"?)
I had considered this, but can't really hard code the 2000. Everything has
to be as flexible as it can. My Year actually comes in as 08, but the
DateTime requires it as Int, which changes 08 to 8.
>
>> However, when returned, it is returning as 23/04/0008 (obviously incorrect, but the MyDate.WeekdayName is returning the correct week day name).
That may break for some other date.
This is what I thought, so, this is why I need to ensure that the date
coming in is somehow understood as a full year.
>
>Later in my code, I have to do a select on a SQL based on the Date, and 23/04/2008 does not match 23/04/0008
Now, I can pass in the string direct (23/04/08) into my SQL and that will work,
SqlServer interprets two-digit years below 50 (I think) as 20xx and higher
values as 19xx. And it will break on years before 1752 or thereabouts.
I sort of worked that out when I passed in my date string.
>
>however, I want to be ABSOLUTELY certain that say for example, 11 May 08 won't be interpreted as 5 Nov 08 which is why I am handling it by splitting my incoming date string.
Any ideas on how I can get it to work the way I want?
Do not pass the date as a string. Use a Parameter to pass the value to sql
and use the (correct) DateTime value directly as the parameter value.
When I say passing to SQL, it is actually in a DataTable.Select() statement,
and I don't know how to pass this as a parameter.
I am loading all the dates locally, then when I need to check against a
date, do a DataTable.Select.
>
Hans Kesting
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Keith |
last post by:
I am having a problem creating a many-to-many-to-many type relationship. It
works fine, but when I create a view to query it and test it, it does not
generate the results I expected.
Below...
|
by: AnkitAsDeveloper [Ankit] |
last post by:
Hi i am serializing a 'ref struct' object as follows :
private: void Seri( String ^path, Object^ obj )
{
FileStream^ fileStrm ;
try
{
//Serialize entire object into Binary stream
|
by: I am Sam |
last post by:
I have created this DateTime object and instanced it I think correctly
DateTime myClubNow1=new...
|
by: Cesar Ronchese |
last post by:
Hi,
I built the sample code showing the problem with dates when viewed at
different machines, different Time Zones and transported via Remoting.
The zip can be downloaded here:
...
|
by: Jason Huang |
last post by:
Hi,
In our C# Windows Form application, we are using the SQL Server 2000 as the
database server.
The Database table MyTable has a field RegistrationDate which represents the
Date a client comes...
|
by: Mike Collins |
last post by:
I cannot get the correct drop down list value from a drop down I have on my
web form. I get the initial value that was loaded in the list.
It was asked by someone else what the autopostback was...
|
by: pranesh.nayak |
last post by:
I'm facing an error:"String was not recognized as a valid DateTime"
whille accessing DateTime from webservice.
And when I try to set DateTime to the same webservice it fails with
error:"Date...
|
by: JFieseler |
last post by:
Hi all,
in a huge project i have the following problem.
I create an object which contains many private members (i know that this is
not correct, but it is a single use migration program). The...
|
by: iulian.ilea |
last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy
into it? I choose this method because I have an application that runs
on more than one server. So, if I used a datetime field...
|
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= |
last post by:
Hi
I am having a problem formatting a string when the time is in format
hh.mm.ss - used in Europe
Parse seems ok when the date uses "/" or "." as seperator
but I get an exception when time...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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: 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,...
|
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...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |