Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Angularjs Get Previous Next Day, Month, Year, Date Time Example

Jun 22, 2015
Introduction

Here I will explain how to get previous day, month, year, time in
AngularJS or get next day, month, year and time in AngularJS. By using “new Date()” function properties like setDate(), setMonth(), setFullYear() we can get current, previous and next day, month, time and year in AngularJS.


To get previous or next day, month, time and year using AngularJS we need to write the code like as shown below


var previousDate = new Date()
previousDate.setDate(previousDate.getDate() - 1)
var nextDate = new Date()
nextDate.setDate(nextDate.getDate() + 1)

If you want to check it in complete example you need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Previous next Day, Month, Year Month Time in Angularjs</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('sampleapp', [])
app.controller('samplecontrol', function ($scope) {
var previousDate = new Date()
previousDate.setDate(previousDate.getDate() - 1)
var nextDate = new Date()
nextDate.setDate(nextDate.getDate() + 1)
var previousMonth = new Date()
previousMonth.setMonth(previousMonth.getMonth() - 1);
var nextMonth = new Date()
nextMonth.setMonth(nextMonth.getMonth() + 1);
var year = new Date()
year.setFullYear(year.getFullYear())
$scope.cdate = new Date();
$scope.pday = previousDate;
$scope.nday = nextDate;
$scope.pmonth = previousMonth;
$scope.nmonth = nextMonth;
$scope.cyear = year;
});
</script>
</head>
<body data-ng-app="sampleapp" data-ng-controller="samplecontrol">
<form id="form1">
<div>
Current Date:<b> {{cdate | date:'dd/MM/yyyy hh:mm:ss a'}}</b><br />
Previous Day:<b> {{pday | date:'dd'}}</b><br />
Next Day:<b> {{nday | date:'dd'}}</b><br />
Previous Month:<b> {{pmonth | date:'MM'}}</b><br />
Next Month:<b> {{nmonth | date:'MM'}}</b><br />
Current Year :<b>{{cyear | date:'yyyy'}}</b><br />
</div>
</form>
</body>
</html>

Live Demo

For live demo check below dates

Current Date: {{cdate | date:'dd/MM/yyyy hh:mm:ss a'}}
Previous Day: {{pday | date:'dd'}}
Next Day: {{nday | date:'dd'}}
Previous Month: {{pmonth | date:'MM'}}
Next Month: {{nmonth | date:'MM'}}
Current Year :{{cyear | date:'yyyy'}}

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

Unknown said...

Its very helpfull

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.