Jump to content
  • 0

Date to text string in format DD/MM/YY with leading 0 for month


Corpcatalog

Question

I have a formula field which produces a batch id from 3 fields.

[@field:Cert]+'-'+CONVERT(VARCHAR,(Day([@field:BatchDeliveryDate]))) + CONVERT(VARCHAR,(Month([@field:BatchDeliveryDate]))) + CONVERT(VARCHAR,( Year([@field:BatchDeliveryDate])),2)+'-'+CONVERT(VARCHAR,([@field:Bags]))

This is not quite right as Month is only 1 character when the month is less than 10 and year is YYYY - I need a 6 digit string for the date

also  Field:Bags is an integer field and doesn't work for this, how do I convert the integer field to text - I get an error message when attempting to convert integer to text string.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hello @Corpcatalog,

this formula gets the 'DDMMYY' from the date:

RIGHT('00' + CONVERT(nvarchar(2), DATEPART(day, [@field:BatchDeliveryDate])), 2)
+
RIGHT('00' + CONVERT(nvarchar(2), DATEPART(month, [@field:BatchDeliveryDate])), 2)
+
RIGHT(CONVERT(nvarchar(4), DATEPART(year, [@field:BatchDeliveryDate])), 2)

This formula adds leading 0 to the day and to the month.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...