Jump to content

Use the First and Last Day of the Month in Search Forms


Recommended Posts

Hi guys, this is not a question but I just want to share a solution that I made using js.

I was needing a way to on load get the first and last day of the current month and use that as my initial search values in a tabular report but I am struggling to find a way without using js.

Here is the script that I came up with:
<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
var date = new Date(), y = date.getFullYear(), m = date.getMonth();
var firstDay = new Date(y, m, 1);
var lastDay = new Date(y, m + 1, 0);

var criteria1 = document.getElementById("Value1_1").value = firstDay.toLocaleDateString("en-US");
var criteria2 = document.getElementById("Value1_2").value = lastDay.toLocaleDateString("en-US");
});
</script>

I got this from https://stackoverflow.com/questions/13571700/get-first-and-last-date-of-current-month-with-javascript-or-jquery and simply use toLocaleDateString to format the values to dd/MM/yyyy instead of the long date used by default.

Just don't forget to inspect the input fields first in the preview to check what is the field's ID then simply change the colored values.
image.png.8e184b40949e0a292add290f94717e63.png

Cheers!

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