Monday, June 29, 2020

javascript boolean function String to boolean conversion

javascript boolean function String to boolean conversion
javascript boolean function String to boolean conversion

Learn about the javascript boolean function :-

Javascript Boolean can have two values (true and false) like any other programming languages.

Boolean function in javascript return the true value if the condition is true. For example : - 
Boolean(13 > 10)

Boolean toString() Method in javascript : - 

toString() function in boolean javascript gives a boolean value as a string.

Syntax : - 

boolean.toString()

javascript boolean toString() function return the value A String, either "true" or "false".

javascript Boolean valueOf() Method : - 

valueOf() function in boolean javascript gives the primitive value of a boolean.
var bool = false;
var y = bool.valueOf();

Syntax : - 

boolean.valueOf()

javascript boolean valueOf() function return the value A Boolean, either true or false

Saturday, June 20, 2020

javascript date function or date format in javascript and convert js date from string

These all are the most using javascript date formate or method with the help of these function users can find out about the date, time (in hour, minute, millisecond) and year also. The user also can convert the Date into a readable string with the date format in javascript.convert

javascript date function or date format in javascript and convert js date from string
javascript date function or date format in javascript and convert js date from string

Date function in Javascript:-

The date function is used to give information about the date and time.
The date object is started with the new Date().

 Javascript works with the opp's so there are four ways to an initialized Date object.

var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);

Now Let's see the Properties of Date Object:-

JavaScript constructor Property:-

constructor property in javascript returns the constructor function for an object and the value of the outcome will be the reference to the function not the name of that function.

Syntax : - 
Date.constructor

JavaScript Date prototype:-

prototype constructor in javascript gives you an opportunity to add new properties and methods to the Date() object.

getDate() function in javascript : - 

getDate function in javascript gives the day of the month of the given date. 

Syntax:-
Date.getDate()

getDay() in javascript : - 

getDay function in javascript gives the day of the week (0 to 6) of the given date. Where 0 is Sunday and 1 is Monday and so on. 

Syntax:-
Date.getDate()

getFullYear() method in javascript : - 

getFullYear() function in javascript gives the year of the given date. 

Syntax:-
Date.getFullYear()

getHours() in javascript : - 

getHours() method in javascript gives the hour of the given date and time. 

Syntax:-
Date.getHours()

getMilliseconds() in javascript : - 

getMilliseconds() method in javascript gives the milliseconds of the given date and time. 

Syntax:-
Date.getMilliseconds()

getMinutes() in javascript : - 

getMinutes() function in javascript gives the minutes of the given date and time.

Syntax:-
Date.getMinutes()

getMonth() in javascript : - 

getMonth() function in javascript gives the month (0-11) of the given date and time based on the local time.
where 0 is January.

Syntax:-
Date.getMonth()

getSeconds() in javascript : - 

getSeconds()gives the output as the seconds of given date and time.

Syntax:-
Date.getSeconds()

getTime() in javascript : - 

getTime() gives the output in milliseconds and it lies between midnight of January 1, 1970  of given date and time.

Syntax:-
Date.getTime()

getTimezoneOffset() in js : - 

getTimezoneOffset()gives the time difference between UTC time and local time, in minutes.

Syntax:-
Date.getTimezoneOffset()

getUTCDate() in javascript : - 

getUTCDate() method in javascript gives day of the month of the given date according to universal time.

Syntax:-
Date.getUTCDate()

getUTCDay() in javascript : - 

getUTCDay() method in javascript gives the day of the week for the gives date according to universal time.

Syntax:-
Date.getUTCDay()

getUTCFullYear() method in javascript : - 

getUTCFullYear() in javascript gives the year of the given date according to universal time (UTC).

Syntax:-
Date.getUTCFullYear()

getUTCHours() in js date function: - 

getUTCHours() gives he hour of the given date and time according to universal time (UTC).

Syntax:-
Date.getUTCHours()

getUTCMilliseconds() in js: - 

getUTCMilliseconds() in javascript gives the milliseconds of the given date and time according to universal time (UTC).

Syntax:-
Date.getUTCMilliseconds()

getUTCMinutes() method in javascript: - 

getUTCMinutes() in javascript gives the  minutes for the given date and time according to universal time (UTC).

Syntax:-
Date.getUTCMinutes()

getMonth() in javascript : - 

getMonth() function in javascript gives the month (0-11) for the given date and time based on the  universal time.

where 0 is January.

Syntax:-
Date.getUTCMonth()

getUTCSeconds() in javascript : - 

getUTCSeconds()gives the output as the seconds(0-59) of given date and time
based on the  universal time.

Syntax:-
Date.getUTCSeconds()

now() date method in javascript : - 

now() function in javascript gives the number of milliseconds since January 1, 1970 00:00:00 UTC.

Syntax:-
Date.now()

parse() date method in javascript : - 

parse() function in javascript use to parses a date string and gives the number of milliseconds since January 1, 1970.

Syntax:-
Date.parse(datestring)

javascript toDateString() method : - 

toDateString() in javascript use to converts the date of a Date object into a readable string.

Syntax:-
Date.toDateString()

toISOString() date method in javascript: - 

toISOString() in javascript use to converts the date of a Date object into a readable string with the help of  ISO standard.

and the iso formate for date:- YYYY-MM-DDTHH:mm:ss.sssZ

Syntax:-
Date.toISOString()

JavaScript toJSON() method: - 

toJSON() in javascript use to converts the date of a Date object into a readable string in JSON format.

and the iso formate for date:- YYYY-MM-DDTHH:mm:ss.sssZ

Syntax:-
Date.toJSON()

toLocaleDateString() date method in javascript: - 

toLocaleDateString() in javascript use to converts the date into a readable string with the help of  locale conventions.

and the iso formate for date:- YYYY-MM-DDTHH:mm:ss.sssZ

Syntax:-
Date.toLocaleTimeString()

JavaScript toLocaleString() method:-

toLocaleString() in javascript use to converts the date into a readable string with the help of locale settings.

Syntax:-
Date.toLocaleString(locales, options)

JavaScript toString() method:-

toLocaleString() in javascript normally use to converts the date into a readable string. 

Syntax:-
Date.toString()

toTimeString() in javascript:-

toTimeString() method use to converts the time portation of date into a readable string.

Syntax:-
Date.toTimeString()

 javascript date UTC method: -

UTC() in javascript gives the number of milliseconds between the given date and midnight of January 1, 1970, according to universal time.

Syntax:-
Date.UTC(year, month, day, hours, minutes, seconds, millisec)

 javascript valueOf() date method: -

valueOf() in javascript gives the primitive value of a Date object.

Syntax:-
Date.valueOf()

Tuesday, June 16, 2020

Standard library math function in c++

C ++ Math function :-

These all are the most used math function in c++. All of these functions are c++ standard library function users just to define it and use it in their program.

Standard library math function in c++
Standard library math function in c++

pow() function in c++ : -

This function used to find the power of any number which is raised to increase the strength of that number. 

Syntax : -

pow(base, exponent) 

Well, c++11 which data type you pass to the pow() function return the result in that same data type.

llrint() in c++

  llrint() function in c++ give the shape to argument into an integral value with the help of current rounding mode.

Syntax : -

llrint(double x);
 It returns the same value for an integer value.

C++ remainder() function:- 

As we know in math theory remainder give the floating-point remainder of numerator/denominator. This function does the same it gives the remainder of numerator/denominator.

Syntax : -

remainder (x, y);

copysign() function in c++ : - 

copysign() function take two argument and give a value with the magnitude of first argument and sign of second argument.

Syntax : -

copysign(x, y);

fma() function in c++ : - 

fma() method in c++ take three argumentfor example x,y andz and give x*y+z without losing precision

Syntax : -

fma(x, y, z);

abs() function in c++ : -

abs function is a well known function in programming language this function used to give the absolute value of the argument.

Syntax : -

abs(x)

fabs() c++ : -

fabs function in c++ also use to give the absolute value but this function return the result value in double, float or long double type.

Syntax : -

fabs(x)

fdim() math function in c++ : -

fdim() function in c++ work with the two arguments and find out about the positive difference between first one and second argument.

Syntax : -

fdim(x, y);

fmin() math function in c++ : -

fmin() in c++  also works with the two arguments and gives the smallest among them.

Syntax : -

fmin(x, y);

Condition: - If any argument is NaN and the other one returned.

fmax() math function in c++ : -

fmax() in function c++  also works with the two arguments and gives the largest among them.

Syntax : -

fmax(x, y);

C++ in hypot():-

hypot() function gives the square root of the sum of square of arguments that are passed to the function.

Syntax : -

hypot(x, y);

nexttoward() math function in c++ : -

c++ standard library function nexttoward() help with the two arguments and give the representable value after x in the direction of y.

Syntax : -

nexttoward(x, y);

it will return the value in double, float, or long double type.

nextafter() function in c++ : -

c++ standard library function nextafter() help with the two arguments and give the representable value after x in the direction of y.

Syntax : -

nextafter(x, y);

its return value in default will be double.

cbrt() function in c++ : -

cbrt() math function in c++ will helps to find out about the cube root of a number. 

Syntax : -

cbrt(x);

sqrt() standard library in c++ : -

sqrt() math function in c++ will helps to find out about the square root of a given number. 

Syntax : -

sqrt(x);

exp() standard library in c++ : -

exp() math function in c++ will help to work with a single argument that can be negative, positive, or zero and gives the exponential raised by the given argument and returns the value in the range of [0, ∞].

Syntax : -

exp(x);

round() standard library in c++ : -

round function gives a integral value that is nearest to the argument this function work with the single argument that is given by the user.

Syntax : -

round(x);

Thursday, June 11, 2020

Advanced functions in SQL server

These all are the advance function in SQL server which are used to manipulate on the database with the help of these function we can get the current user name, user id, and more.

Advanced functions in SQL server
Advanced functions in SQL server

IFF() function in SQL: - 

"IIF() function" is a conditional function like if in any programming. IFF() function return the value if the condition is true or another value if a condition is FALSE. 

Syntax:-
IIF(condition, value_if_true, value_if_false)

ISNULL() function in SQL:- 

ISNULL() is used to give the specified value if the expression is NULL.

Syntax:-
ISNULL(expression, value)

The expression is tested to know that the given expression is NULL or not. If it's null then return the specified VALUE as shown in syntax.

ISNUMERIC() function in SQL Server:- 

ISNUMERIC() is used to test that given expression is numeric.

Syntax:-
ISNUMERIC(expression)

NULLIF() function in SQL Server:- 

NULLIF() function gives you NULL if two expressions are equal, otherwise, it returns the first expression.

Syntax:-
NULLIF(expr1, expr2)

SESSION_USER in SQL Server:- 

SESSION_USER function helps you to know about the current user in the SQL Server database.

Syntax:-
SESSION_USER

SESSIONPROPERTY() in SQL Server:- 

SESSIONPROPERTY() function in SQL gives the setting for a specified option for SQL SESSION.

Syntax:-
SESSIONPROPERTY(option)

Option In SESSIONPROPERTY()
  •     ANSI_NULLS
  •     ANSI_WARNINGS
  •     QUOTED_IDENTIFIER
  •     ARITHABORT
  •     CONCAT_NULL_YIELDS_NULL
  •     NUMERIC_ROUNDABOUT
  •     ANSI_PADDING

SYSTEM_USER in SQL Server:- 

SYSTEM_USER  function does the same as SESSION_USER but the only difference is SYSTEM_USER gives the login name for the current user.

Syntax:-
SYSTEM_USER

USER_NAME() for SQL Server:- 

USER_NAME() function in SQL gives the name of the user depends on the specified id in the SQL database. If id is not specified then it will give the current user name.

Syntax:-
SYSTEM_USER

Tuesday, June 9, 2020

Conversion functions in SQL

 These all are the function in SQL which is used to converts an expression from one data type to another data type and these all function are known as Conversion "Functions in SQL".
 
Conversion functions in SQL
Conversion functions in SQL


CAST function in SQL : - 

CAST in SQL helps to converts an expression from one data type to another data type. If the conversion fails, CAST function would come back with a mistake. Otherwise, it'll give the conversion value.

Syntax  : - 
CAST( expression AS type [ (length) ] )

length: - length of the resulting data type like char, int, float, etc.

Example : - 
SELECT CAST(13.35 AS int);
Result: 13          (result is truncated)

SELECT CAST(14.56 AS float);
Result: 14.56       (result is not truncated)

SELECT CAST(14.7 AS varchar);
Result: '14.7'

SELECT CAST(149.6 AS varchar(4));
Result: '15.9'

SELECT CAST('15.6' AS float);
Result: 15.6

SELECT CAST('2014-05-02' AS datetime);
Result: '2014-05-02 00:00:00.000'

CONVERT function in SQL : -

CONVERT method in SQL does the same as CAST function "converts an expression from one data type to another data type."
But the syntax is different in this method tell the type of data type in which you wish to convert the expression to and type used to tell about the format used to convert between data types.

Syntax  : - 
CONVERT( type [ (length) ], expression [ , style ] )

Example : -

SELECT CONVERT(int, 13.85);
Result: 13          (result is truncated)

SELECT CONVERT(float, 13.85);
Result: 13.85       (result is not truncated)

SELECT CONVERT(varchar, 15.7);
Result: '15.7'

SELECT CONVERT(varchar(4), 15.7);
Result: '15.7'

SELECT CONVERT(float, '15.6');
Result: 15.6

SELECT CONVERT(datetime, '2014-05-02');
Result: '2014-05-02 00:00:00.000'

SELECT CONVERT(varchar, '05/02/2014', 101);
Result: '05/02/2014'

TRY_CAST function in SQL Server : -

TRY_CAST function also does the same work as the previous two functions did but this function will return NULL for any error. Otherwise, it will return the converted value.
Syntax  : - 
TRY_CAST( expression AS type [ (length) ] )

Example : -

SELECT TRY_CAST(13.85 AS int);
Result: 13
(result is a truncated int value)

SELECT TRY_CAST(13.85 AS float);
Result: 13.85
(returned as a float value and is not truncated)

SELECT TRY_CAST('14 Main St.' AS float);
Result: NULL
(result is NULL because conversion failed since this string value can not be converted to a float)

SELECT TRY_CAST(15.6 AS varchar);
Result: '15.6'
(result is returned as varchar)

SELECT TRY_CAST(15.6 AS varchar(2)); 
Result: NULL
(result is NULL because conversion failed since the value will not fit in a 2 character varchar)

SELECT TRY_CAST('2018-09-13' AS datetime);
Result: '2018-09-13 00:00:00.000'
(result is returned as a datetime)

TRY_CONVERT function in SQL Server : -

TRY_CONVERT function could be used at the place of CONVERT function in SQL because this function also used to "converts an expression from one data type to another data type." and TRY_CONVERT function will return NULL for any error. Otherwise, it will return the converted value.

Syntax  : - 
TRY_CONVERT( type [ (length) ], expression [ , style ] )

Example : -

SELECT TRY_CONVERT(int, 14.80);
Result: 14


SELECT TRY_CONVERT(float, 14.75);
Result: 14.75
(result is returned as a float value and is not truncated)

SELECT TRY_CONVERT(float, '14 Main St.');
Result: NULL


SELECT TRY_CONVERT(varchar, 15.6);
Result: '15.6'
(result is returned as a varchar)

SELECT TRY_CONVERT(varchar(2), 15.6); 
Result: NULL


SELECT TRY_CONVERT(datetime, '2018-09-13');
Result: '2018-09-13 00:00:00.000'


SELECT TRY_CONVERT(varchar, '2018-09-13', 101);
Result: '09/13/2018'
(result is returned as a varchar with a style of 101 - mm/dd/yyyy (US standard) )

Sunday, June 7, 2020

Read about Time/Date function in SQL

Learn about all date function which is used to manipulate in the SQL server with the help of Date function in SQL for example - CURRENT_TIMESTAMP function in SQL, DATEADD, DATENAME.

Read about Time/Date function in SQL
Read about Time/Date function in SQL


CURRENT_TIMESTAMP function in SQL : -

SQL gives a function to the user which helps to return the current date and time in the SQL server and that function is known as CURRENT_TIMESTAMP function.

Syntax : - 
CURRENT_TIMESTAMP

This function gives date and time in the format 'yyyy-mm-dd hh:mm:ss.mmm'.

See the example : - 
SELECT CURRENT_TIMESTAMP;
Result: '2014-05-01 14:19:55.918'

DATEADD function in SQL : -

DATEADD function in SQL helps to give a date after adding or subtracting the interval from the date.

dateadd "function in SQL"
dateadd function in SQL

Syntax:- 
DATEADD( interval, number, date )

Example : -

SELECT DATEADD(year, 1, '2014/05/29');
Result: '2015-05-29 00:00:00.000'

SELECT DATEADD(year, 1, '2014/05/29');
Result: '2015-05-29 00:00:00.000'
SELECT DATEADD(year, 1, '2014/05/29');
Result: '2015-05-29 00:00:00.000'
SELECT DATEADD(year, -1, '2014/03/23'); Result: '2013-03-23 00:00:00.000' SELECT DATEADD(month, 1, '2014/09/18'); Result: '2014-09-18 00:00:00.000' SELECT DATEADD(month, -1, '2014/04/28'); Result: '2014-03-28 00:00:00.000' SELECT DATEADD(day, 1, '2014/04/28'); Result: '2014-04-29 00:00:00.000' SELECT DATEADD(day, -1, '2014/04/28'); Result: '2014-04-27 00:00:00.000'

DATEDIFF function in SQL : -

DATEDIFF function tells about the between two date values, based on the interval specified.


datediff "function in sql"
datediff function in SQL


Syntax:- 
DATEDIFF( interval, date1, date2 )

The interval used to calculate the difference between date1 and date2.

Example : - 


SELECT DATEDIFF(year, '2012/01/18', '2014/01/28');
Result: 2

SELECT DATEDIFF(yyyy, '2010/04/28', '2012/04/28');
Result: 2

SELECT DATEDIFF(yy, '2010/04/28', '2012/04/28');
Result: 2

SELECT DATEDIFF(month, '2014/01/01', '2014/04/28');
Result: 3

SELECT DATEDIFF(day, '2014/01/01', '2014/04/28');
Result: 117

SELECT DATEDIFF(hour, '2014/04/28 08:00', '2014/04/28 10:45');
Result: 2

SELECT DATEDIFF(minute, '2014/04/28 08:00', '2014/04/28 10:45');
Result: 165

DATENAME in SQL : -

DATENAME function in SQL gives the specified part of the of a given date, as a string value


Syntax:- 
DATENAME( interval, date )

it will return the result in the string.

Example : - 


SELECT DATENAME(year, '2014/04/28');
Result: '2014'

SELECT DATENAME(yyyy, '2012/04/28');
Result: '2012'

SELECT DATENAME(yy, '2010/04/28');
Result: '2010'

SELECT DATENAME(month, '2014/01/28');
Result: 'Jan'

SELECT DATENAME(day, '2014/04/19');
Result: '19'

SELECT DATENAME(quarter, '2014/04/28');
Result: '2'

SELECT DATENAME(hour, '2014/04/28 09:49');
Result: '9'

SELECT DATENAME(minute, '2014/04/28 09:49');
Result: '49'

SELECT DATENAME(second, '2014/04/28 09:49:12');
Result: '12'

SELECT DATENAME(millisecond, '2014/04/28 09:49:12.726');
Result: '726'

DATEPART in SQL : -

DATEPART function in SQL gives the specified part of the of a given date, as an integer value.


Syntax:- 
DATEPART( interval, date )

it will return the result in the integer.

Example : - 


SELECT DATENAME(year, '2014/04/28');
Result: '2014'

SELECT DATENAME(yyyy, '2012/04/28');
Result: '2012'

SELECT DATENAME(yy, '2010/04/28');
Result: '2010'

SELECT DATENAME(month, '2014/01/28');
Result: '1'

SELECT DATENAME(day, '2014/04/19');
Result: '19'

SELECT DATENAME(quarter, '2014/04/28');
Result: '2'

SELECT DATENAME(hour, '2014/04/28 09:49');
Result: '9'

SELECT DATENAME(minute, '2014/04/28 09:49');
Result: '49'

SELECT DATENAME(second, '2014/04/28 09:49:12');
Result: '12'

SELECT DATENAME(millisecond, '2014/04/28 09:49:12.726');
Result: '726'

DATEPART in SQL : -

DAY function tells about the day of the month (between 1 to 31) given a date value.


Syntax:- 
DAY( date_value )

Example : - 


SELECT DAY('2014/04/22');
Result: 22

SELECT DAY('2014/03/23 10:05');
Result: 23

SELECT DAY('2014/04/11 10:05:18.621');
Result: 11

GETDATE SQL function : -

GATEDATE function in SQL gives you the current date and time just like the CURRENT_TIMESTAMP function.


Syntax:- 
GETDATE ( )

Example : - 

SELECT GETDATE();
Result: '2014-04-28 18:17:28.160'

GETUTCDATE SQL function : -

GETUTCDATE function for SQL server returns the current UTC date and time.


Syntax:- 
GETUTCDATE ( )

Example : - 
SELECT GETUTCDATE();
Result: '2014-04-29 00:27:58.657' 

MONTH Function in SQL : -

MONTH function tells about the MONTH of the month (between 1 to 12) given a date value.


Syntax:- 
MONTH( date_value )

Example : - 


SELECT MONTH('2014/02/28');
Result: 2

SELECT MONTH('2014/01/31 10:05');
Result: 1

SELECT MONTH('2014/10/01 10:05:18.621');
Result: 10

MONTH Function in SQL : -

MONTH function tells about the four-digit year (in number) given a date value.


Syntax:- 
YEAR( date_value )

Example : - 


SELECT YEAR('2012/04/28');
Result: 2012

SELECT YEAR('2009/03/31 10:05');
Result: 2009

SELECT YEAR('2011/12/01 10:05:18.621');
Result: 2011