Showing posts with label JavaScripts. Show all posts
Showing posts with label JavaScripts. Show all posts

Thursday, May 27, 2021

Calculate the difference between two dates - Javascript

 

Calculate the difference between two dates

There are multiple options to calculate the difference between dates.

1. getDateDiff

The easiest approach is to use getDateDiff. See this calculation:

getDateDiff('{date2}','{date1}','y')

In this calculation:

  • '{date2}'  = the variable name of the date field that contains the most recent date 
  • '{date1}' = the variable name of the date field with the older date
  • 'y' = the unit in which the difference is returned, i.e. 'years' in this case

Replace date1 and date2 with your own variable names. Make sure to keep the '{ }' (curly brackets surrounding the variables and the quotation marks). You can change 'y' to any unit you want to use:

  • Year: 'y'
  • Day: 'd'
  • Hour: 'h'
  • Minutes: 'm'


2. Date difference with Moment objects  

You can also create Moment objects and then calculate the difference:  

var admission = moment('{date1}', 'DD-MM-YYYY'); 
var discharge = moment('{date2}', 'DD-MM-YYYY');
discharge.diff(admission, 'days');

Instead of days you can also use: 'months' or 'years', or 'weeks' depending on what you want to measure. Check this template in the calculation helper.  


3. Date difference with today

You can also calculate the difference between now (today) and a date of choice, e.g. if you want to know how many days passed between today and the date the patient had their last visit:

var dateofvisit = moment('{visit}', 'DD-MM-YYYY');
var today = moment();
today.diff(dateofvisit, 'days');

In this calculation '{visit}' is the variable name of the date of the visit. Replace this variable with your own variable. Check this template in the calculation helper.

Note: This calculation will always update when you open the step where it is located in a record, since it calculates the actual moment at the time you are in that step.


4.  Converting number of days to number of weeks and days

If the number of days is known, it is possible to easily convert the number of days to the number of the weeks with the following template:

var amountWeeks = {amountDays}/7
var remainingDays = {amountDays}%7;
remainingDays = remainingDays.toFixed(0)
Math.floor(amountWeeks) + " weeks, " + (remainingDays) + " days"

In this calculation {amountDays} is the variable in which the number of days is collected. Test this template using calculation helper.


5. Calculating the difference between two dates using date and time field

If you are using a date and time field and would like to output the difference between the two dates in days, hours and minutes, use the following template:

var m1 = moment('{admission}', 'DD-MM-YYYY HH:mm'); 
var m2 = moment('{discharge}', 'DD-MM-YYYY HH:mm'); 
var m3 = m2.diff(m1,'minutes'); 
var m4 = m2.diff(m1,'h'); 


var numdays = Math.floor(m3 / 1440); 
var numhours = Math.floor((m3 % 1440) / 60); 
var numminutes = Math.floor((m3 % 1440) % 60); 
numdays + " day(s) " + numhours +"h " + numminutes +"m";

Sunday, June 21, 2015

Google Map Api Get current location Latitude and Longitude in JavaScript

Introduction:
Here I will explain how to get latitude and longitude from address Google map api using JavaScript in website or Google maps autocomplete address textbox to get latitude and longitude without map example. By using google.maps.places.Autocomplete class we can implement Google places autocomplete textbox and display selected address latitude and longitude details.

 To implement places or address autocomplete textbox using Google maps Google API we need to write the code like as shown below


 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Maps Api Get Current Location Latitude and Longitude</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script type="text/javascript">
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var geolocation = new google.maps.LatLng(
position.coords.latitude, position.coords.longitude);
var location = "Latitude: " + geolocation.A + "
"
;
location += "Longitude: " + geolocation.F;
document.getElementById('lblResult').innerHTML = location
});
}
}
</script>
</head>
<body>
<div style="margin-top:200px; margin-left:200px">
<span>Location:</span>
<input type="button" id="btnGet" value="Get Latitude & Longitude" onclick="geolocate()" /><br /><br />
Current Location Latitude & Longitude:<br /><br />
<label id="lblResult" />
</div>
</body>
</html>

Sunday, January 11, 2015

jQuery Image effect on Mouseover with Opacity light and dark

Introduction:

Here I will explain how to use jQuery to change image opacity on mouseover using jQuery or change opacity of image on hover using jQuery.

Here is the aspx code with the jQuery function.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Change Image Opacity on Mouse Over</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$("#logoimage").css("opacity", 0.5);
$("#logoimage").hover(function() {
$(this).animate({ opacity: 1.0 }, 500);
}, function() {
$(this).animate({ opacity: 0.5 }, 500);
});
})
</script>
</head>
<body>
<form id="form1">
<div>
<img id="logoimage"  src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJyV9uXDRC1UmF-EQ41rhDHVaTYkw5SbI9-L2CBRsODFY_Rt9Iue4BhyjKg0GqNgz0JTsubQQ5rxr8LMhCwda44MXaYh2PQoZJrx1VlyhZI2AMJBNLxk1EwjOL74NvkZ4HC_RijQj9VWs/s1600/aavv.JPG" />
</div>
</form>
</body>
</html>




jQuery Caps Lock On or Off in JavaScript

 Introduction:

Here I will explain in jQuery how to check caps lock ON or OFF in JavaScript.
Generally to check caps lock on or off in page load it’s not possible we can analyze key code only in key press using jQuery or JavaScript.

Here is the function for check Caps Look is ON or OF

function checkcapslockon(e) {
var charKeyCode = e.keyCode ? e.keyCode : e.which;
var shiftKey = e.shiftKey ? e.shiftKey : ((charKeyCode == 16) ? true : false);
if (((charKeyCode >= 65 && charKeyCode <= 90) && !shiftKey) || ((charKeyCode >= 97 && charKeyCode <= 122) && shiftKey)) {
alert('Caps Loc On');
}
else {
alert('Caps Loc Off');
}
}

How to Remove Row in Table using jQuery


Introduction:
Here I will explain in how to remove row in table using jQuery or jQuery remove current selected row from table or how to delete table row using jQuery.

The below is  jQuery function to remove the Table Row
<script type="text/javascript">
$(function() {
$('input[type="button"]').click(function(e) {
var row = $(this).closest('tr');
row.remove()
})
})
</script>

JavaScript - Division using Math.Ceil function

Introduction

Here I will explain how to number division in JavaScript or jQuery using Math.ceil() method. Math.ceil() method will rounds number upwards to next nearest integer.

Declaration of Math.ceil() method
Generally we will use Math.ceil() method like as shown below

var result = Math.ceil(45 / 4);
alert(result + ", " + div);

The complete Example using the JavaScritp Math.ceil function.

Tuesday, May 20, 2014

Asma Qureshi - Sr.Software Developer

Its Asma Qureshi, Working in DUBAI.
Senior/lead level software / Web developer with 9 years experience developing applications / Webs with broad set of technologies and domains. Love solving hard problems, fixing impossible bugs and learning new things.

Objective: Work that is challenging, solve real problems and deliver value .I have keen interest to make easl UI Aps

Computing skills: Programming experience with C#, VB.NET, ASP.NET ,JavaScript, PHP, SQL Server 2008. 2010 ,  Crystal Report,  Development experience with Web, Windows platforms. Expertise in system architecture, design and development using object oriented design principles and relational database model.

Technical Tools: Visual Studio, HTML/HTML5, CSS, .NET Framework, JQury, ASP.NET, ASP.NET MVC, Windows Forms, WPF, Silverlight, WCF, XML, web services in asp.net , Microsoft SQL Server, IIS.

Sunday, May 19, 2013

Javascript Validation for Email

<script type='text/javascript'>
function emailValidator(elem, helperMsg){
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if(elem.value.match(emailExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}
</script>
<form>
Email: <input type='text' id='emailer'/>
<input type='button'
    onclick="emailValidator1(document.getElementById('emailer'), 'Not a Valid Email')"
    value='Check Field' />
</form>