1
<!-- Date Range - Script  -->
<script>
$(function()
{

    // Set the default dates
    var startDate   = Date.create().addDays(-6),    // 7 days ago
        endDate     = Date.create();                // today

    var range = $('.range');

    // Show the dates in the range input
    range.val(startDate.format('{MM}/{dd}/{yyyy}') + ' - ' + endDate.format('{MM}/{dd}/{yyyy}'));

    range.daterangepicker
    ({
        startDate: startDate,
        endDate: endDate,
        ranges:
        {
            'This Month': [Date.create().addMonths(-1), 'today']
        }
    }
});
</script>

I am using a sugar.min.js. I want to get the current month which starts from date 1 to current date.

This This Month': [Date.create().addMonths(-1), 'today'] will give me the date from 04/04/2014 to 05/04/2014. I don't want the previous month date, instead i want this 05/01/2014 to 05/04/2014

5
  • I've never used Sugar, but can you create a Date then set its day component to 1? Commented May 4, 2014 at 14:15
  • @James using Sugar or without sugar.js? Commented May 4, 2014 at 14:18
  • actually i only want this using sugar js. Commented May 4, 2014 at 14:18
  • With sugar. Just reading to docs, it looks like you can do Date.create() .beginningOfMonth(). Commented May 4, 2014 at 14:19
  • @James where you read this doc? this solved my problem. please submit your answer so i can accept it Commented May 4, 2014 at 14:22

1 Answer 1

1

A couple of options from sugar's manipulating dates documentation:

Date.create().set({day: 1})
Date.create().beginningOfMonth()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.