473,799 Members | 3,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime Hell

Hi, I'm soon finishing my first app, and I learned a lot :-)

I'm still having trouble with dates...

When I pull a date from SQL Server, I store it in a DateTime variable
and when I want to display it I do this : _date.ToString( "dd/MM/yyyy")
and this works fine...

But how do I asign to my DateTime _date variable a string entered by
user aka 15/12/2004 ?

I tried some code floating around with no success...

So, what do I need to perform something like this:

_date = SOME_FUNCTION(" 15/12/2004");

TIA
Nov 16 '05 #1
6 1561
Franck Diastein wrote:

Hi, I'm soon finishing my first app, and I learned a lot :-)

I'm still having trouble with dates...

When I pull a date from SQL Server, I store it in a DateTime variable
and when I want to display it I do this : _date.ToString( "dd/MM/yyyy")
and this works fine...

But how do I asign to my DateTime _date variable a string entered by
user aka 15/12/2004 ?

I tried some code floating around with no success...

So, what do I need to perform something like this:

_date = SOME_FUNCTION(" 15/12/2004");

TIA


Look at DateTime.Parse( string, IFormatProvider )
Nov 16 '05 #2
Try this:
DateTime d1 = new DateTime(2004, 10, 15); // year, month, day
// or
DateTime d2 = DateTime.Parse( "10/15/2004");
Hope this helps mate.

Cheers,

Shariq Khan
sh****@shariqkh an.com

"Franck Diastein" <fd*******@eusk altel.net> wrote in message
news:ON******** ******@TK2MSFTN GP09.phx.gbl...
Hi, I'm soon finishing my first app, and I learned a lot :-)

I'm still having trouble with dates...

When I pull a date from SQL Server, I store it in a DateTime variable and
when I want to display it I do this : _date.ToString( "dd/MM/yyyy") and
this works fine...

But how do I asign to my DateTime _date variable a string entered by user
aka 15/12/2004 ?

I tried some code floating around with no success...

So, what do I need to perform something like this:

_date = SOME_FUNCTION(" 15/12/2004");

TIA

Nov 16 '05 #3
I've been testing and it's works the way you tell me, but I still don't
know how to do it without specifiying time... :-(

Bret Pehrson wrote:
Franck Diastein wrote:
Hi, I'm soon finishing my first app, and I learned a lot :-)

I'm still having trouble with dates...

When I pull a date from SQL Server, I store it in a DateTime variable
and when I want to display it I do this : _date.ToString( "dd/MM/yyyy")
and this works fine...

But how do I asign to my DateTime _date variable a string entered by
user aka 15/12/2004 ?

I tried some code floating around with no success...

So, what do I need to perform something like this:

_date = SOME_FUNCTION(" 15/12/2004");

TIA

Look at DateTime.Parse( string, IFormatProvider )

Nov 16 '05 #4
Franck Diastein wrote:

I've been testing and it's works the way you tell me, but I still don't
know how to do it without specifiying time... :-(
string [] dateFormats = { "dd/MM/yyyy" };
DateTime.ParseS tringExact(date String, dateFormats, ...);

Bret Pehrson wrote:
Franck Diastein wrote:
Hi, I'm soon finishing my first app, and I learned a lot :-)

I'm still having trouble with dates...

When I pull a date from SQL Server, I store it in a DateTime variable
and when I want to display it I do this : _date.ToString( "dd/MM/yyyy")
and this works fine...

But how do I asign to my DateTime _date variable a string entered by
user aka 15/12/2004 ?

I tried some code floating around with no success...

So, what do I need to perform something like this:

_date = SOME_FUNCTION(" 15/12/2004");

TIA

Look at DateTime.Parse( string, IFormatProvider )

Nov 16 '05 #5
I can't beleive it !!!

In fact it's ASP.NET...

Finally, I have adapted a VB code to do this:

using System.Globaliz ation;

DateTimeFormatI nfo _Format = getDateTimeForm atInfo("fr-FR");
DateTime _date = DateTime.Parse( "25/12/2004",_Format);

private static DateTimeFormatI nfo getDateTimeForm atInfo(string p_Culture){

DateTimeFormatI nfo _dtf;
try
{
CultureInfo _ci = new CultureInfo(p_C ulture);
_dtf = _ci.DateTimeFor mat;
return _dtf ;

}
catch {
return null;
}
}
Thanx

Shariq Khan wrote:
Try this:
DateTime d1 = new DateTime(2004, 10, 15); // year, month, day
// or
DateTime d2 = DateTime.Parse( "10/15/2004");
Hope this helps mate.

Cheers,

Shariq Khan
sh****@shariqkh an.com

"Franck Diastein" <fd*******@eusk altel.net> wrote in message
news:ON******** ******@TK2MSFTN GP09.phx.gbl...
Hi, I'm soon finishing my first app, and I learned a lot :-)

I'm still having trouble with dates...

When I pull a date from SQL Server, I store it in a DateTime variable and
when I want to display it I do this : _date.ToString( "dd/MM/yyyy") and
this works fine...

But how do I asign to my DateTime _date variable a string entered by user
aka 15/12/2004 ?

I tried some code floating around with no success...

So, what do I need to perform something like this:

_date = SOME_FUNCTION(" 15/12/2004");

TIA


Nov 16 '05 #6
Thanx

Bret Pehrson wrote:
Franck Diastein wrote:
I've been testing and it's works the way you tell me, but I still don't
know how to do it without specifiying time... :-(

string [] dateFormats = { "dd/MM/yyyy" };
DateTime.ParseS tringExact(date String, dateFormats, ...);

Bret Pehrson wrote:
Franck Diastein wrote:
Hi, I'm soon finishing my first app, and I learned a lot :-)

I'm still having trouble with dates...

When I pull a date from SQL Server, I store it in a DateTime variable
and when I want to display it I do this : _date.ToString( "dd/MM/yyyy")
and this works fine...

But how do I asign to my DateTime _date variable a string entered by
user aka 15/12/2004 ?

I tried some code floating around with no success...

So, what do I need to perform something like this:

_date = SOME_FUNCTION(" 15/12/2004");

TIA
Look at DateTime.Parse( string, IFormatProvider )

Nov 16 '05 #7

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

Similar topics

22
2313
by: Jim Hubbard | last post by:
I am reposting a portion of a thread that I am involved in under a new topic because it seems that there are still people that believe the whole "DLL Hell" myth. I hope I can shed some light on this deception for some..... "Michael A. Covington" <look@ai.uga.edu.for.address> wrote in message news:%23tKbygELFHA.576@TK2MSFTNGP15.phx.gbl... > > "Jim Hubbard" <reply@groups.please> wrote in message
10
1781
by: Dennis D. | last post by:
Trying to write an itinerary program. Got date and time from date time picker Converted it to date variables to extract the date and the time The form has first a textbox displaying the starting date and time via the picker. The next few text boxes allow user input of hours and minutes for elapsed time of occurring events Each text box subtracts or adds from the previous box to reveal a new date time
4
6422
by: Michael Meckelein | last post by:
Hello, Wondering, if C# (framework 2.0) does not support parsing DateTime timezones in three letter acronyms. I would like to parse date strings like "2005 Nov 01 11:58:47.490 CST -6:00" but it seems C# does not support the timezone letters (CST). I suppose to use the symbol ZZZ for the timezone letters, but MSDE pointed out that it is not supported in C#, isn't it?
11
9841
by: Peter Holschbach | last post by:
Hi, I've the following line of code: result = DateTime.ParseExact("1999-12-01T23:59:59Z", "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture); where I get in result "result" "02.12.1999 00:59:59" instead of teh expected "01.12.1999 23:59:59" Anybody a idea ?
0
10490
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
10260
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
10243
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,...
1
7570
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.