Selasa, 23 Agustus 2016

[Step 10] Learn to command the query "arithmetic operators and time" in MySQL ss


In this post, BeCoding.tk will teach you some new query commands, that is:
1.Operator calculation
2.Date
3.DateDiff


1.Operator calculation
Arithmetic operators on mysql there are some like  +,-,*,/,DIV,and %(MOD).
"+" Is used to add more than one data.
"-" Is used to reduce the data with the other data.
"*" Is used to multiply the data with the other data.
"/" Is used to divide one data with other data.
"Div" is used to perform calculations for the division without remainder.
"Mod" is used to search for the remainder of the calculation.


Examples of its application:
"Select 1 + 1;" -> Will get results 2
"Select 1-1;" -> Will get results 0
"Select 1 * 5;" -> Will get results 5
"Select 4/2;" -> Will get results 2
"Select 5 div 2;" -> Would getting the 2 (obtained from the 5 = 2 + 2 + 1 calculated the amount of numbers 2 No 2)
"Select 5% 2;" ->Would getting the 1(obtained from the 5 = 2 + 2 + 1 calculated for the remainder of 2 is 1)

   
2.Date
date in mysql is divided into three parts, namely days, months, and years.
If we write "Date (now ());" it will mendapatakan result the current date on your computer. 

If we just wanted to get a date alone, it can be written down "Select day (now ());" 
If we just wanted to get a month only then it can be written "Select month (now ());"
If we just want to get year alone, it can be written down "Select year (now ());"

*Note: now -> Symbolizes the current time (in your computer)

3.DateDiff
Datediff used to find the difference of two dates. how writing is datediff (new_date,old_date)
For example, the difference in the date of 10 August 2016 to 11 August 2016 is the difference one day.
then the command is "select datediff ('2016-08-11', '2016-08-10');"


That is some query commands related to the operation and time calculations.Thank you for visiting and reading to the end of this post. Hopefully this article can help you all become more powerful programmer.
 

Tidak ada komentar:

Posting Komentar