I'm using the bootstrap-datepicker and I'm running in to this weird issue.
it works fine, but when I selects a month (E.g May) it shows the selected month as March. (2 months back), Always there is a 2 months gap between,
What is in the date select and months shown in the date-picker popup.
My date-picker is set to only show months and it starts from 1 Jan 2018,
and following is the config
var date = new Date('January 1, 2018');
$('.datepicker').datepicker({
format: "MM yyyy",
minViewMode: 'months',
autoclose: true,
startDate: date
});
What seems to be going wrong here ?
$('.datepicker').datepicker({
format: "MM yyyy",
viewMode: "months",
minViewMode: "months",
startDate: new Date('Jan 1, 2018')});
Try this out. This might help you
Although this might not help for your specific scenario, I did run into the same issue when I included the time.
So format of dd/mm/yyyy was doing fine but once I switched to dd/mm/yyyy hh:mm it added 2 months (December instead of October).
All I eventually had to do was switch to the format dd/mm/yyyy hh:ii as shown in the documentation.
That saved me from switching to a newer version (which is still old when looking at it now, but the github project of datetimepicker points to that link).
Related
I tried to get the start date of a specific week in Moment.js from the week number and year by doing moment().year(...).isoWeek(...).startOf('isoWeek')
But It seems that this function is not always returning the correct date.
For example when I live in England and a week always starts on a monday.
We should get 31 Dec 2018 when we ask for the first day of week 1, 2019.
This wasn't the case on 31 Dec 2018 as the result I received was 30 Dec 2019 as the begin date of week 1, 2019. See example
I think I found the solution I was looking for
moment()
.isoWeekYear(year)
.isoWeek(week)
.startOf('week')
Please note that, as i18n section of the docs states:
By default, Moment.js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.js for later use.
So if you want to use en-gb locale you have explicitly load it (in the browser, you can use en-gb.js file or moment-with-locales.js and then set locale using moment.locale('en-gb')).
You don't have to use year() setter, because it sets the year to 2019 and moment().year(2019).isoWeek(1) gives you the first isoweek of the 2020. You can create a moment object for a given year using moment({y: year}) instead.
You have to use week() instead of isoWeek if you want locale dependent results:
Because different locales define week of year numbering differently, Moment.js added moment#week to get/set the localized week of the year.
The week of the year varies depending on which day is the first day of the week (Sunday, Monday, etc), and which week is the first week of the year.
Here a full code sample:
// Set locale to British English
moment.locale('en-gb');
var year = 2019;
var firstMonday = moment({y: year}) // get first day of the given year
.week(1) // get the first week according locale
.startOf('week'); // get the first day of the week according locale
// Show result
console.log(firstMonday.format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment-with-locales.min.js"></script>
You can use format() to display the value of a moment object.
I have two dates in my _type in Kibana. When I find my documents in the Discover tool, the date shown is one month earlier than it should be. Here, I should see February in the Table view:
When I switch to the JSON view, I it looks like my date is correct:
Kibana is using the incorrect January date in all visualizations as well.
Here is the mapping I'm using for my dates:
{ "type": "date", "format": "YYYY-MM-DD HH:mm:ss" },
What have I done wrong?
Your format on your date/time is wrong.
You are using YYYY-MM-DD instead of yyyy-MM-dd.
Specifically it's having issues because DD means "day of year", so it's always in January.
In the agenda week options on the left side - there is that am/pm I want to remove/replace that with just 01:00, 02:00 so on.
check out that example and switch to the week view - on the left side you will find 6am, 7am etc...
fiddle
Thanks for your time.
I downloaded the language pack from here
and then I've added this:
lang: "de",
to the full_calendar js code.
Set the timeFormat option
timeFormat: 'H(:mm)'
TimeFormat Docs
I'm working with Moment.js for my first time. I tried to retrieve the date of the first day of the week, and in Europe this is normally Monday. Whatever I do, I get Sunday as result of the first day of the week.
I tried to set-up different languages (local or globally), but to no avail. I use the langs.min.js file from the moment.js github page. The language file of "en-gb" and "fr" has the line of code:
dow : 1, // Monday is the first day of the week.
So I would get the date of monday when I ask for the first day of the week right? I keep getting Sunday as output.
// Create moment object
var localLang = moment();
// Set language to french
localLang.lang('fr');
// Test language
localLang.lang(); // Output: fr
// Retrieve first day of the week and format it
var dow = localLang.startOf('week').format('dddd DD-MM-YYYY'); // Output: dimanche 14-04-2013
Dimanche is french for Sunday.. As you see, moment.js can use the language file succesfully but doesn't use the day of the week configuration
JSfiddle with moment.js and langs.js to test:
JSFiddle
edit:
I can get the date of Monday instead of Sunday with day(1) instead of startOf('week'). But using day(0)I still get Sunday as a result. Why isn't monday the first day of the week, as configured in the language files.
For anyone who come across this question lately, moment now support lang method to set locale specific setting.
Setting first week to be Monday:
moment.lang('zh-cn', {
week : {
dow : 1 // Monday is the first day of the week
}
});
var date = moment().weekday(0); // date now is the first day of the week, (i.e., Monday)
We are working on adding locale aware weekdays, but it hasn't been finished yet.
https://github.com/timrwood/moment/issues/613#issuecomment-13786429
I have a Report that I send a parameter to as 'WeekStart'. This is based on a selection a user makes on a datepicker.
I'm using the following to extract the week of the year:
=DatePart("ww", Parameters!WeekStart.Value)
The problem I'm having is that when I pick the day 03/01/2012 (dd/MM/yyyy format), the week of the year is returned as 9, which would technically be true had the date been 03/01/2012 with a dateformat of MM/dd/yyyy.
I've tried using CDate, FormatDateString etc but nothing seems to be working. I either get #Error or it returns as the 9th week of the year.
Any suggestions?
What you can do is this:
use YourDatabase
go
set dateformat dmy
go
That will set the date format for your database, and that should get your DATEPART function working as expected.
SET DATEFORMAT (MSDN)