Jump to content
  • 0

Converting Date into text format


Ammar

Question

hello, i have date of birth field in a datapage, that need to convert into a text format, then use as number in formula, 

for example, if my DOB is 01/22/1999, i need to store the value 01221999 in a different field in the data source table , i have tried the following formula " STR (DATEPART(DD,[@field:Virtual_DOB])) + STR (DATEPART(MM,[@field:Virtual_DOB])) + STR (DATEPART(YYYY,[@field:Virtual_DOB])) ", but i get the result as 01 22 1999, removing the forward slash but apparently still keeping the structure . 

thank you for your help, i appreciate it.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hello @Ammar,

The whitespaces are related to the nature of the STR() function.

If you need to keep trailing zeros in days and months, you can test one of these formulas:

1) This one exrtacts the parts of the date, converts them into the string, and keeps trailing zeros for values that are less than 10:
For European date format dd/MM/yyyy

RIGHT('00' + CAST(DATEPART(day, [@field:Date]) AS nvarchar),2) + 
RIGHT('00' + CAST(DATEPART(month, [@field:Date]) AS nvarchar),2) +
CAST(DATEPART(year, [@field:Date]) AS nvarchar)

For the US date format MM/dd/yyyy:

RIGHT('00' + CAST(DATEPART(month, [@field:Date]) AS nvarchar),2) +
RIGHT('00' + CAST(DATEPART(day, [@field:Date]) AS nvarchar),2) + 
CAST(DATEPART(year, [@field:Date]) AS nvarchar)

2) This one converts the date to a string and replaces the dash signs with an empty string:

103 in the formula stands for the European date format dd/MM/yyyy.

REPLACE(CONVERT(nvarchar, [@field:Date], 103), '/', '')

101 in the formula stands for the US date format MM/dd/yyyy:

REPLACE(CONVERT(nvarchar, [@field:Date], 101), '/', '')
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...