Jump to content
  • 0

Timestamp using Java


GLENNSTER
 Share

Question

Hi

I was hoping someone could help me with creating some javascript. I have no knowledge of it whatsoever but it appears to be the only solution to my problem without using a pop up calendar (which seems to take forever on my pc to come up).

I want a timestamp to be put against all my submissions, but I only want DD/MM/YY recorded, and not DD/MM/YY HH:MM as is currently the set up in caspio. I wish to sort my results by day, but at the minute if I do a sort based on the current timestamp they will sort by day by hour by minute. I want my results to show the best price per day (eg Monday) as opposed to by minute the data was entered.

I have tried to amend the sample javascript given in the tutorial but I am not having much success. Can anyone give me a helping hand?

This was my last attempt (please don't laugh):- (my timestamp field is called "date", and it is an update datapage)

//(1) Declaration and initialization

Stamp = new Date();

var v_TimeStamp;

//(2) Construct the value of the v_TimeStamp variable in the format mm/dd/yyyy

v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear();

//(3) Field name - Date is referred with a prefix - EditRecord

document.forms[0].UpdateDate.value=v_TimeStamp;

Any help is greatly appreciated.

Thanks

Glenn

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

You should be able to use the "toDateString" method to convert the full (MM/DD/YY/HH/MM/SS) date into a string containing just the "date" (and not time) elements.

To do this, you would modify the code you posted with the following change (called out in bold):

//(3) Field name - Date is referred with a prefix - EditRecord

document.forms[0].UpdateDate.value=v_TimeStamp.toDateString();

One caution/concern: The above function will convert the "v_TimeStamp" variable to a string formatted like "Mon Oct 13 2008", but Caspio may not accept that string as a valid "Date" value in it's table, so you may get something like an "invalid data type" error when you submit.

I hope this helps.

Mitch Hollberg

Morrison Analytics

Link to comment
Share on other sites

  • 0

Thanks for trying Hollberg. Either it doesn't like the code or it doesn't like something I am doing. I entered the code below into the footer section -

Stamp = new Date();

var v_TimeStamp;

v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear();

document.forms[0].UpdateDate.value=v_TimeStamp.toDateString();

but no date is being recorded in my table.

I am using a text field as my form element for my date. Ideally I would like this to be hidden but I am using text field at the minute to try and get the date format sorted.

Thanks again for the effort.

Glenn

Link to comment
Share on other sites

  • 0

It's hard to know for sure what is causing the problem without seeing all of your code and field names, but here is one other guess as to what could be causing the problem...

Is your timestamp field named "date" (lowercase) or "Date" (uppercase)? If the timestamp field name, as defined in your table, is "date", then your code would need to end with the string:

document.forms[0].Updatedate.value=v_TimeStamp.toDateString();

rather than

document.forms[0].UpdateDate.value=v_TimeStamp.toDateString();

Here's hoping that the second time's the charm...

Mitch Hollberg

Link to comment
Share on other sites

  • 0

Hi Glenn,

Your modified Java Script should work on your DataPage if you fix some part of the code.

What you have:

//(1) Declaration and initialization

Stamp = new Date();

var v_TimeStamp;

//(2) Construct the value of the v_TimeStamp variable in the format mm/dd/yyyy

v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear();

//(3) Field name - Date is referred with a prefix - EditRecord

document.forms[0].UpdateDate.value=v_TimeStamp;

Fisrt error: You have missed to close the parantheses after getFullYear

Second error: To refer a field which is either in a details page of a search and report or it is in an update web form you should call it as document.forms[0].EditRecordDate, be careful about the case sensitivity of the field name so it could be document.forms[0].EditRecorddate

If this is a Capture web form rather than an update or details form you should call the field as: document.forms[0].InsertRecorddate

So the code should be:

//(1) Declaration and initialization

Stamp = new Date();

var v_TimeStamp;

//(2) Construct the value of the v_TimeStamp variable in the format mm/dd/yyyy

v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear());

//(3) Field name - Date is referred with a prefix - EditRecord

document.forms[0].EditRecordDate.value=v_TimeStamp;

Try this out and hopefully it works. If it did not work yet, give me the URL where you have deployed it so I can better understand what type of DataPage you have and some other stuff.

Regards,

Bahar M.

Link to comment
Share on other sites

  • 0

Hello @GLENNSTER,

You can also use a calculated field in generating a Timestamp, check this documentations:

https://howto.caspio.com/datapages/reports/advanced-reporting/calculations-in-forms-and-reports/

And check this function references you can use in the Formula and calculated field:
https://howto.caspio.com/function-reference/

I hope this helps :) 

~WatashiwaJin~

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

×
×
  • Create New...