Jump to content
  • 0

Extract Day Of The Week From Date


juancoffee
 Share

Question

Hello

I have two fields in my submission form - date and day.

The customer selects date (via calendar pop up text field). 

I need the day field to automatically be populated by the day of the week from the date input (so someone inputs 25/12/2013 and the day field automatically says 'Wednesday' or whatever).

 

Currently, I'm tackling this in a very roundabout way, by passing a long date to a report data page and then using rules (if date contains 'Monday' then hide section 1 etc).

This is laborious and requires the user to click again on a url link.

 

There must be an easier way. Does anyone know how?

Ideally some javascript to just take the day of the week from the date field would be good.

If that's not possible, then javascript that basically says "if [@field:date] contains 'Monday' then go to data page XXXXXXX" 

 

All help appreciated.

 

Thanks

 

Duncan

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Try the following code to get the day automatically if the date is selected from a submission form

=======

Remember to change the element id "InsertRecordFieldNameofDate" and "InsertRecordFieldNameofDayName"

<script>
function myFunction()
{
var sub_date = document.getElementById("InsertRecordFieldNameofDate").value;
var d = new Date(sub_date); 
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var x = weekday[d.getDay()];
document.getElementById("InsertRecordFieldNameofDayName").value = x; 
}

document.getElementById("InsertRecordFieldNameofDate").addEventListener("change", myFunction);
</script>

Link to comment
Share on other sites

  • 0

Hello Duncan,

 

One workaround would be to create the submission form and have the user submit the date. Upon submit, he can be redirected to another Details DataPage where you will pass the ID from the submission form as a parameter. You can have a pre-defined criteria for this Details page and add a calculated field with the following SQL code.This will display the details to the user upon submit with the day of the date entered.

 

SELECT DATENAME(dw,[@field:Date_submitted])

 

I hope this helps.

 

 

 

 

post-14176-0-06914300-1382739764_thumb.p

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