Jump to content

Store only date, month and year instead of timestamp


Recommended Posts

Hi,

I need to store date when record was submitted. I know that I can stamp record, using a "time stamp" hidden field, but I need to store only date, month and year. I don't need time, because I'm not able to use this field in grouping data on Chart report.

Thanks for help!

Link to comment
Share on other sites

Hi Mylene,

Try using the following script:

<SCRIPT LANGUAGE="JavaScript">
 Stamp = new Date();
 var v_TimeStamp;
 v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear());

document.getElementById("InsertRecordDate_field").value=v_TimeStamp;
</SCRIPT>

Please add your field name instead of Date_field. 

Hope it helps.

Link to comment
Share on other sites

  • 5 years later...

Hello, I pull up the date from the Timestamp by creating a formula field on a table level and then inserting the following formula:

CONVERT(varchar(10), [@field:Timestamp], 101)

101 is a date format I commonly use. Sometimes, I use 110 if I want a dash on it instead of slash.

Link to comment
Share on other sites

  • 5 months later...

Hi - I would like to add on this post. In case, you would like to get the month using DATEPART() and add leading zero, you may use these formulas:

RIGHT('0' + CAST(DATEPART(month, [@field:DATE]) AS VARCHAR(10)), 2)

or 

RIGHT('0' + CONVERT(VARCHAR(2), DATEPART(MM, [@field:DATE])), 2)


Result:

January = 1 to 01
February = 2 to 02

Since the DATEPART() function returns an integer, leading zero's will always disappear and need to be manually added like so.


Reference:
https://www.w3schools.com/sql/func_sqlserver_datepart.asp

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
Reply to this topic...

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