Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting DateString to Date

Status
Not open for further replies.

Nordlund

Programmer
Jul 17, 2001
458
SE
Hi all..

I want to convert the swedish datetime(as string) to English format (as DateTime format). My computer is of course configured to use english date.

I know that StrToDateTime would work normally, but not in this case, because we are crossing the "national boundaries".

The following example would work IF the string and the computer's date format was the same.

//Nordlund
 
You mention an example, but it is not part of the post...

Could you post an example of the Swedish date string? Cheers,
Nico
 
Sorry mate...

The string is formatted like this: '2002-10-23 10:57:00'
and I want to convert it to TDateTime format...

I can manually decode this string using EncodeDate and EncodeTime, but it would be nice to have a builtin function to solve this...

Maybe like this:
function CustomStrToDateTime(const Format, DateStr: String): TDateTime;

// Nordlund
 
Hi.

Try to:
ShortDateFormat := 'yyyy-mm-dd hh:mm:ss';
StrToDateTime('2002-10-23 10:57:00');

The ShortDateFormat variable is responsible for date format in StrToDateTime function, I think.
 
Yep, that might do the trick... Thanks for the tip mate.

There is only one catch, but It's easy to fix.

The variable ShortDateFormat is an Delphi global variable, and it should never be changed (At least what i have heard).

TempShortDate := ShortDateFormat;
ShortDateFormat := 'yyyy-mm-dd hh:mm:ss';
StrToDateTime('2002-10-23 10:57:00');
ShortDateFormat := TempShortDate;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top