Jump to content
  • 0

Add Date to String in Formula


DesiLogi

Question

8 answers to this question

Recommended Posts

  • 0
On 12/21/2017 at 4:57 PM, Vitalikssssss said:

LEFT(CONVERT(VARCHAR, [@field:Date], 120), 10)

@Vitalikssssss this is SO helpful!! Thanks very much! At first I deleted the "left" and "10" because I didn't understand their purpose, but now I get it :) For anyone wondering, here's an explanation for why it's useful:

The "LEFT" at the start of the formula gives instruction to only keep the left side of whatever is contained in the brackets that follow, and the "10" gives instruction to keep the first 10 characters (to the left, in this case; you can also use "right" in other cases). So you have year (4 characters), plus month (2 characters) plus day (2 characters) plus 2 forward slashes: ex. "2018/03/22", and that's a total of 10 characters. If you didn't limit the date to 10 characters, the time would be included as well.

In case anyone wants the time included in the date-turned-string, just remove the "LEFT("   and the   ",10)from Vitalikssssss's answer above. And if you want only the time, use "right" instead of "left" and replace 10 with the number of time characters (don't forget to include ":" as part of your character count).

Link to comment
Share on other sites

  • 0

I have also faced a similar issue, but I wanted to get the date into a more usable format, here I am using UK format, but you can move the day and month around - 

Day / Month / Year

RIGHT(LEFT(CONVERT(VARCHAR, [@field:JobDate], 120), 10),2)

+ '/' + RIGHT(LEFT(LEFT(CONVERT(VARCHAR, [@field:JobDate], 120), 10),7),2)

+ '/' +LEFT(LEFT(CONVERT(VARCHAR, [@field:JobDate], 120), 10),4)

 

Hopefully this helps getting the date formatted within a formula field outside a datapage. 

Link to comment
Share on other sites

  • 0

Hi! Just to add, you can check this Convert function in our Function Reference and in w3schools page:
- https://howto.caspio.com/function-reference/#:~:text=data type specified-,Convert,-(new data type
- https://www.w3schools.com/sql/func_sqlserver_convert.asp

Lastly, you can visit this article for more information about the VARCHAR:
- https://www.sqlshack.com/sql-varchar-data-type-deep-dive/

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...