1 (edited by derek 2017-03-24 11:08:35)

Topic: strftime and leading zero

Hello Dmitry,
Is there a way to format strftime to remove the leading zero from the month?
Using strftime('%m', xdate) results in '01' for January, '02' for February etc and what I need is '1' , '2' etc.
I have tried strftime('%-m', xdate) and strftime('%#m', xdate) but neither seems to be supported.
Thanks for any help,
Derek.

Re: strftime and leading zero

Hello Derek

Can this help you .

Example code : Showing all of the date field formatting data types
var
  myDate : TDateTime;
  formattedDateTime : string;

begin
  // Set up our TDateTime variable with a full date and time :
  // 5th of June 2000 at 01:02:03.004  (.004 milli-seconds)
  myDate := EncodeDateTime(2000, 6, 5, 1, 2, 3, 4);

  // Date only - numeric values with no leading zeroes (except year)
  DateTimeToString(formattedDateTime, 'd/m/y', myDate);
  ShowMessage('              d/m/y = '+formattedDateTime);

  // Date only - numeric values with leading zeroes
  DateTimeToString(formattedDateTime, 'dd/mm/yy', myDate);
  ShowMessage('           dd/mm/yy = '+formattedDateTime);

  // Use short names for the day, month, and add freeform text ('of')
  DateTimeToString(formattedDateTime, 'ddd d of mmm yyyy', myDate);
  ShowMessage('  ddd d of mmm yyyy = '+formattedDateTime);

  // Use long names for the day and month
  DateTimeToString(formattedDateTime, 'dddd d of mmmm yyyy', myDate);
  ShowMessage('dddd d of mmmm yyyy = '+formattedDateTime);

  // Use the ShortDateFormat settings only
  DateTimeToString(formattedDateTime, 'ddddd', myDate);
  ShowMessage('              ddddd = '+formattedDateTime);

  // Use the LongDateFormat settings only
  DateTimeToString(formattedDateTime, 'dddddd', myDate);
  ShowMessage('             dddddd = '+formattedDateTime);

  // Use the ShortDateFormat + LongTimeFormat settings
  DateTimeToString(formattedDateTime, 'c', myDate);
  ShowMessage('                  c = '+formattedDateTime);
end;

JB

Re: strftime and leading zero

Hi Jean,

Thanks for the list - it will be very useful (I always have problems formatting dates - my bête noire!).
But what I am trying to do is part of an SQL QUERY, not part of a script;  as I understand it, you have to use strftime within SQL QUERY.
From google searches, I thought that a strftime format of '%#m' would remove the leading zero of a month but it doesn't work for me.
.
Dmitry,

Do you know of any other options?

Derek.

Re: strftime and leading zero

Hello.


Check it out

ltrim(strftime('%m', xdate), '0')
Dmitry.

Re: strftime and leading zero

Hi Dmitry,
I tried ltrim but was using an incorrect format.
Thanks for your help,
Derek.