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

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 1548
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****@shariqkhan.com

"Franck Diastein" <fd*******@euskaltel.net> wrote in message
news:ON**************@TK2MSFTNGP09.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.ParseStringExact(dateString, 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.Globalization;

DateTimeFormatInfo _Format = getDateTimeFormatInfo("fr-FR");
DateTime _date = DateTime.Parse("25/12/2004",_Format);

private static DateTimeFormatInfo getDateTimeFormatInfo(string p_Culture){

DateTimeFormatInfo _dtf;
try
{
CultureInfo _ci = new CultureInfo(p_Culture);
_dtf = _ci.DateTimeFormat;
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****@shariqkhan.com

"Franck Diastein" <fd*******@euskaltel.net> wrote in message
news:ON**************@TK2MSFTNGP09.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.ParseStringExact(dateString, 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
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...
10
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...
4
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...
11
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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
0
BarryA
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...
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...

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.