I am new to angularJS and now i would like to how to add the year from current date.
Let's say i can get the user DOB and i want to add the year+1.
I have tried by using,
$scope.userdob = $rootScope.user.dob;
$scope.userdob.add(1,'years');
but it's not working.
Can anyone help me to know about this logic with example ?
TIA..,
You should use .setDate() function to increment the days.
I created an angular example here http://codepen.io/heshamelghandour/pen/WwodMP
It looks like $rootScope.user.dob is an instance of moment from the moment.js library. I think your main problem is angular's change detection cannot detect when you mutate this instance. Because the instance remains the same but the internal underlying date value does change. Thus I'd suggest:
$scope.userdob = $rootScope.user.dob.clone().add(1,'years').valueOf();
That way angular will get a regular JavaScript Date object instead of a moment instance and it's change detection will work correctly.
FYI to accomplish the same with a standard javascript Date instance you can do:
var userdob = new Date();
userdob.setYear(userdob.getFullYear() + 1)
To advance the year by 1.
Use .setDate() function to increment the days and instead of +1 day and add +365 days it will give you date after 1 year.
Related
I am using react big calendar and I am using the start days and end days of the week for my api call
here's the function I am calling to get events
getEvents(calendarId,firstday,lastDay);
this function creates the api url to hit using the calendar id and the dates for first day and last day.
so, if the calendar shows the week as 20th august - 27 august
then first day is 20-08-2017 and last day is 27-08-2017
and my api url becomes
calendar/events/?start="20-08-2017"&end="27-08-2017"
for next week i.e 28-08-2017 to 3-08-2017
I want to get dates automatically from the calendar
so I can use it in my api call?
the problem is that I am quite new to react-big-calendar and I dont know how to get the dates from there.
I'd really appreciate it if you could provide some suggestions or advice or even point me where to look.
I have been through the documentation but couldnt get what I want.
EDIT:
I am using onNavigate as shown below to call the function that makes the api call
onNavigate={() => {
actions.calendar.getEvents(this.props.params.calendarId, firstday, lastday);
}}
Try to change your callback to accept the current start date of your calendar:
onNavigate={(date) => ...}
and calculate the requered date range for your API call e.g. using moment JS lib.
i want to push time in my database but when i push time my $scope.moreadditems variable its save wrong time please help me i am using angularjs
check when i enter time 9:00 AM why this show different time
check jsfiddle
i am adding below time its working fine add in table
but when i click show details its show different time
and also this time in database why
input[time] will always output datetime of 1970-01-01 + the time you inputed, see documentation here.
If you just want to keep the time part, you can use filter date to pick it, and don't forget to inject $filter first.
var timeHHMM = $filter('date')(time, 'hh:mm');
refer demo.
When we select a date from the angular Datepicker and my model is empty first time, then it selects one day back date.
If we assign current date first time in the model, then it works fine.
Check here
and here
It seems that in both, changing the date format seemed to fix the problem.
Also, welcome to Stack Overflow :)
I have a textbox and using data-ng-model="EmpDetails[0].DateOfJoining" So what happens here is the date comes along with the time and I only want the date.
I have seen multiple place where you use {{EmpDetails[0].DateOfJoining | date: 'MM/dd/yyyy'}} but what I want is within the model, its got a 2 way bind.
Any help will be appreciated.
I have problem with richfaces calendar. I want to see only year and month so i made datePattern="yyyy/MM", which works fine until i want to change date.
When i click on button and calendar pop up the current value disappear. If i don't select date the value is null. I tried to save old date in my bean but problem remains because when i open calendar it is always set to todays date.
Problem occur only when i don't put dd(days) in datePatern
<rich:calendar value="#{myBean.date}" datePatern="yyyy/MM" />
Tnx for help in advance
I got answer on richfaces forum so i will copy it also here
I guess rich:calendar is not the right choice at you case although rich:calendar may be bound to probably any object type provided that you supply custom converter a day ordinal still should be supplied because it's a part of the date maybe you would do better with a h:selectOneMenu to specify a month and a h:inputText to define a year instead of "incomplete" rich:calendar