Posts

Showing posts from 2019

Get Dynamic Clock In or clock time in SQL

Image
 Now, I am going to generate dynamic time like real punch time for Clock In or Clock Out. When we implement punch time functionality. Create a View for Get Random value in SQL. Because SQL not allow RAND() function in user define function. So I am creating a view for this CREATE VIEW vw_getRANDValue AS SELECT RAND() AS Value Create a user define function to get real punch time. I am passing date of punch and time range in time format. GO CREATE FUNCTION [dbo].[FnGetPunchTime] (@WorkingDate DATETIME,@timeRangeBegin time,@timeRangeEnd time) RETURNS DATETIME AS BEGIN     DECLARE @Result AS DATETIME;    DECLARE @RandomTime  DATEtime, @TimeSpanInMSec int = datediff(MILLISECOND,@timeRangeBegin, @timeRangeEnd) SELECT @RandomTime=DATEADD(MILLISECOND,(SELECT Value FROM vw_getRANDValue) *  @TimeSpanInMSec,@timeRangeBegin) SELECT @Result=CONVERT(DATETIME, CONVERT(varchar, @WorkingDate, 23)   + ' ' + CONVERT(varchar, @RandomTime, 114))     RETURN (@Result); END I am putting

How to add or update query string parameter to current url in Javascript

  In this post, I will let you know how to add or update query string parameter to current URL using Javascript. function  updateQueryStringParameter(uri, key, value) {          var  re =  new  RegExp( "([?&])"  + key +  "=.*?(&|$)" ,  "i" );          var  separator = uri.indexOf( '?' ) !== -1 ?  "&"  :  "?" ;          if  (uri.match(re)) {            return  uri.replace(re,  '$1'  + key +  "="  + value +  '$2' );         }          else  {            return  uri + separator + key +  "="  + value;         }   }   In above example, you will need to pass three argument, first will be your current URL and second will be key which you want to add/update and last argument will be the value of key. using below example how to use and update a herf attribute  $( ".user_nav" ).each( function  () {                   var  $that = $( this );         

Set date format in MVC/.Net Core using unobtrusive js

We will include some js for validation . @Scripts . Render ( "~/Scripts/jquery-3.1.1.js" ) @Scripts . Render ( "~/Scripts/jquery.validate.min.js" ) @Scripts . Render ( "~/Scripts/jquery.validate.unobtrusive.min.js" ) @Scripts . Render ( "~/Scripts/moment.js" ) we need moment.js so we will install or add put moment js file in out solution. And then we will finally add fix for date format parser in any js call after unobtrusive and page load $( function  () {     $.validator.methods.date = function  (value, element) {          return   this .optional(element) || moment(value, "DD / MMYYYY" , true ).isValid();     }}); I have set date format “dd/MM/yyyy”. moment js need date format in upper case so I have use as “DD/MMM/YYYY”.

Calculate Dynamic Current Calendar / Financial Year In C#

I need a financial / calendar year based on current or today's date time We need some time dynamically financial year or calendar year base on current date. Suppose any company or organization have calendar year like 1 st  Jan to 31 th  Dec, 1 st  Feb to 31 th  Jan, 1 st  Apr to 31 Mar, 1 st  Oct to 31 th  Sep etc...… So we need calculate current calendar year base on calendar start month of organization /company. Examples Suppose Today's date is 5 th  Feb 2017 and organization calendar start month is Jan(01) then current calendar year we will be 1 st  Jan 2017 to 31 th  Dec 2017. Suppose Today's date is 10 th  Mar 2017 and organization calendar start month is Apr(04) then current calendar year we will be 1 st  Apr 2016 to 31 th  Mar 2017. Suppose Today's date is 10 th  May 2018 and organization calendar start month is Apr(04) then current calendar year we will be 1 s t Apr 2018 to 31 th  Mar 2019. public   static  DateTime GetCurrentCalendarStartDate(