Thank you. You learn something everyday. I was not aware of this functionality. This does exactly what I need!

 

Kevin

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, February 28, 2005 2:19 AM
To: Burton, Kevin; nant-users@lists.sourceforge.net
Subject: RE: [Nant-users] Format conversion to string with leading zeros.

 

Kevin,

 

It's probably simpler to do this sort of manipulation with script rather than using NAnt tasks and functions.  Try something like:

 

    <script language="C#" prefix="format" >

        <code><![CDATA[                

                         [Function("format-date")]

        public static string FormatDate(DateTime date)

        {

            return date.ToString("yyyyMMdd");

        }

        ]]></code>

    </script>

 

You would then call this as:

 

    <echo message="The date is: ${format::format-date(datetime::now())}" />

 

Cheers,

 

Bill

 

-----Original Message-----
From: Burton, Kevin [mailto:[EMAIL PROTECTED]
Sent: 26 February 2005 06:56
To: nant-users@lists.sourceforge.net
Subject: [Nant-users] Format conversion to string with leading zeros.

 

OK. I had a very simple problem in calling date functions and getting the year, month, and day parts of the date. Now that I have that solved I would like to solicit help with my next task. I want to convert a datetime to a specific string format. Right now I want to convert to a string YYYYMMDD, with leading zeros as appropriate. While I can call get-month to get the month portion of a date I cannot format the integer into a string with a leading zero. I have a similar problem with the day portion. Any suggestions?

 

Thank you.

 

Kevin



UK businesses use 2 million tonnes of paper each year.
THINK before you PRINT this email.
______________________________________________________________

CONFIDENTIALITY NOTICE

This communication and the information it contains is intended for the person or organisation to
whom it is addressed. Its contents are confidential and may be protected in law. Unauthorised use,
copying or disclosure of any of it may be unlawful. If you are not the intended recipient, please
contact us immediately.

The contents of any attachments in this e-mail may contain software viruses, which could damage your
own computer system. While Marlborough Stirling has taken every reasonable precaution to minimise
this risk, we cannot accept liability for any damage, which you sustain as a result of software
viruses. You should carry out your own virus checking procedure before opening any attachment.

Marlborough Stirling plc, Registered in England and Wales
Registered No. 3008820,
Jessop House, Jessop Avenue, Cheltenham, Gloucestershire, GL50 3SH
Tel: 01242 547000 Fax: 01242 547100
http://www.marlborough-stirling.com

Reply via email to