1

I am looking for a library or snippet to convert Date/Time format strings from Delphi to .Net. This is for Delphi version 2007.

For example, Delphi 2007 specifies "m" as month, whereas .Net uses "M". However, in Delphi, if the "m" follows an "h", then it represents a minute value.

Are any available, or do I have to roll my own?

4
  • What exactly are you talking about? In memory or in a file? What string encoding? What version of Delphi? (They made some big changes to string format handling a couple years ago.) Commented Jul 6, 2010 at 13:42
  • I added some clarification - Thanks Mason. Commented Jul 6, 2010 at 13:47
  • Aha! You're talking about format strings. I thought you were talking about string formats. :P Commented Jul 6, 2010 at 15:02
  • In other words, your input is a string suitable for using with Delphi's FormatDateTime function, and the output should be a string suitable for using with the DateTime.ToString method, right? Commented Jul 6, 2010 at 15:05

2 Answers 2

3

ShineOn has a function to do just that:

ConvertDelphiDateTimeFormat(const aFormat: DelphiString): DelphiString;

It also has the inverse:

ConvertClrDateTimeFormat(const aFormat: DelphiString): DelphiString;

It's found in the "Date Functions (SysUtils).pas" file.

The code does indicate it's not 100%

Conversions between date formats:

This is close, but there are some cases where the mapping must be approximate.

For Delphi formats, this means

  • am/pm maps to ampm (that is, must use system setting)
  • a/p is based on current settings, not hardcoded to 'a' or 'p'
  • no control over case in the am/pm or a/p strings
  • no options for how to represent era, they all map to gg
  • no support for z -- it maps to fractional seconds with 3 decimals (zzz)

For CLR formats, this means

  • no support for single-digit years, they map to 2 digit years.
  • no support for 12-hour clock when there is no am/pm symbol, 24-hour is used.
  • no support for fractional seconds, they map to milliseconds (zzz)
  • no support for time zone offsets
Sign up to request clarification or add additional context in comments.

2 Comments

It doesn't seem to handle the following: Delphi=yyyymmdd hh:mm, .Net=yyyyMMdd HH:MM I believe it should be: Delphi=yyyymmdd hh:mm, .Net=yyyyMMdd HH:mm Note the incorrect handling of the minutes field.
Since you have the code it might be worth fixing that specific problem and submitting a patch back the the project.
1

You have to roll your own.

Use these links to make the mapping:

  1. .NET Custom Date and Time Format String
  2. .NET Standard DateTime Format Strings
  3. Delphi SysUtils.FormatDateTime specifiers

--jeroen

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.