How to add month to date in angularjs? - javascript

Hi I am developing web application in angularjs. I am developing one form and i have one textbox with date picker. I am using 720kb date picket pluggin. https://github.com/720kb/angular-datepicker I want users to allow dates after 1 month. For example if today is august 14 then i want to enable dates only after september 14. I have added moment.js and put
var date = moment();
date.add(1, 'months');
console.log(date);
$scope.maxdate=date.d;
In html i have date-min-limit="maxdate". How ever this is not going to work. I got date-max-limit="" method from the above mentioned document. May i know what i am doing wring in the above code? Can someone help me to fix this? Thank you.

date-min-limit="" expects a string version of short date
In your controller
$scope.maxdate = moment().add(1, 'M').format('MM/DD/YYYY');
In your html
date-min-limit="maxdate"

If you use bootstrap, you can use this pluggin https://github.com/uxsolutions/bootstrap-datepicker
In its example,demos, you can set start date.

Related

jquery fullcalendar control date as server date

I need to set today date is server date but in fullCalendar it is displaying local system date as today date.
I have set server date with gotoDate option as following.
$('#calendar').fullCalendar('gotoDate', currentDate);
but it is not working properly as i click on the today button it is displaying local system date.
please help me.
You can set the default date in fullcalendar:
https://fullcalendar.io/docs/current_date/defaultDate/
you have to use moment plugin (which is a third party plugin and you have to include it separately in your project before fullcalendar)
https://fullcalendar.io/docs/utilities/Moment/
I set the current date on click of today button. Code is as following.
$('.fc-today-button').click(function () {
$('#calendar').fullCalendar('gotoDate', currentDate);
});

Bootstrap datetime picker picking day before selected

I am using this bootstrap datetime picker. I noticed that when I choose a day and convert the milliseconds using var d1 = new Date(milliseconds); it is converted into the day before my selected day. Is there a particular reason for this?
Example:
I select Tuesday, October 1st:
I log the date object after it is converted:
You must convert it into a Unix timestamp , which is a better way of tracking date/time.
Use new Date('your_date_string').getTime() / 1000 which gives you the timestamp or using PHP (strtotime) .
The date object that is being logged for you is probably coming from your system/browser settings(local).
Do not use JavaScript date and time calculations in web applications unless you ABSOLUTELY have to.
While you have the timestamp, cross-check if you are getting the correct time.

Displaying Day and Date from feed

How do I display the following as a a Day, Month?
"2013-05-28T00:00:00.0000000" as Tuesday, May 28 ?
thanks.
So since you have tagged the question as both javascript and python
I will recommend two libraries that solve the issue.
Using http://momentjs.com/ you can solve your problem as follows here
Using http://delorean.readthedocs.org you can solve your problem as follows here
If in python you can do it like this:
from datetime import datetime
datetime.strptime('2013-05-28T00:00:00.0000000','%Y-%m-%dT00:00:00.0000000').strftime('%A %b, %d')
>>>'Tuesday May, 28'
This will output in your current locale language.
Hope this helps!
If you want to do this is javascript it will look something like the following
var d = new Date();
d.toISOString();
document.write(d);

Jumping a week or month in the jQuery UI Datepicker

PetersenDidIt did a great job answering this question.
He showed how to use a link to update the jQueryUI Datepicker's selected date by one day. His solution was:
$('a#next').click(function () {
var $picker = $("#datepicker");
var date=new Date($picker.datepicker('getDate'));
date.setDate(date.getDate()+1);
$picker.datepicker('setDate', date);
return false;
});
I am trying to modify it to do the same thing for a week or month. According to the set date api I should be able to use "+1m" and "+1w" to skip a month or week. I can't seem to get the code working with anything other than "+1".
Thoughts?
you can use the same code you have.
when you want one week do like this:
date.setDate(date.getDate()+7);
when you want one month you can do:
date.setMonth(date.getMonth()+1);
Try using FireBug script debugging. Might be some JS exception being generated.

How to change the date format in JavaScript?

I am using one jquery date picker,
with using picker i am getting date in like this format
Friday, May 21, 2010
Now i want to add one day in this date so i think, i can only do if i change the date in exact format like
21/5/2010
I want to only convert that bcz i want to add one day to the particular date.
So what do u suggest me? How can I do that?
Can i do without converting it ?
thanks in advance....
Take a look at http://docs.jquery.com/UI/Datepicker#option-dateFormat
datejs may be useful to you.
In addition to the formatting options given by others, you should add using date objects rather than to the string representation of the date object.
I.E.
// add 5 days to today
var myDate=new Date();
myDate.setDate(myDate.getDate()+5);
I think you need to detail what jQuery plugin do you use.
Is it this one? http://jqueryui.com/demos/datepicker/
If so, then when you cann getDate method, you'll get Date object representing a date. You can easily manipulate it.
The date format has nothing to do with how dates are stored; it only affects the way dates are displayed. JavaScript has a native Date object and jQuery UI's Datepicker allows to access such object:
http://jqueryui.com/demos/datepicker/#method-getDate
Once you have a Date object, you can alter it to suit your needs:
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date
Finally, you can feed it back into Datepicker:
http://jqueryui.com/demos/datepicker/#method-setDate

Categories

Resources