snipt

Ctrl+h for KB shortcuts

MySQL

Find MySQL Collation and Charsets

1
2
3
4
USE database_name;

SHOW VARIABLES LIKE "character_set_database";
SHOW VARIABLES LIKE "collation_database";
https://snipt.net/embed/fdaa71b9921a6e4991919d5e578a1791/
/raw/fdaa71b9921a6e4991919d5e578a1791/
fdaa71b9921a6e4991919d5e578a1791
mysql
MySQL
4
2019-07-19T03:54:41
True
False
False
/api/public/snipt/41726/
find-mysql-collation-and-charsets
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">USE</span> <span class="n">database_name</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">SHOW</span> <span class="n">VARIABLES</span> <span class="k">LIKE</span> <span class="s2">&quot;character_set_database&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">SHOW</span> <span class="n">VARIABLES</span> <span class="k">LIKE</span> <span class="s2">&quot;collation_database&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
charset, collation, mysql, utf8

SCSS

Vertical gradient background, with alpha opacity and IE support. Compass+Sass style.

1
2
3
4
5
6
$color_start: rgba(255,255,255,1);
$color_stop:  rgba(255,255,255,0);
#gradient {
    @include background(filter-gradient(ie-hex-str($color_start), ie-hex-str($color_stop))); // For IE
    @include background(linear-gradient($color_start, $color_stop));
}
https://snipt.net/embed/7cd0787f39a05f476c04ac0400a57c22/
/raw/7cd0787f39a05f476c04ac0400a57c22/
7cd0787f39a05f476c04ac0400a57c22
scss
SCSS
6
2019-06-29T10:44:47
True
False
False
/api/public/snipt/39983/
vertical-gradient-background-with-alpha-opacity-and-ie-support-compasssass-style
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nv">$color_start</span><span class="o">:</span> <span class="nf">rgba</span><span class="p">(</span><span class="mi">255</span><span class="o">,</span><span class="mi">255</span><span class="o">,</span><span class="mi">255</span><span class="o">,</span><span class="mi">1</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$color_stop</span><span class="o">:</span> <span class="nf">rgba</span><span class="p">(</span><span class="mi">255</span><span class="o">,</span><span class="mi">255</span><span class="o">,</span><span class="mi">255</span><span class="o">,</span><span class="mi">0</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nn">#gradient</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">@include</span><span class="nd"> background</span><span class="p">(</span><span class="nf">filter-gradient</span><span class="p">(</span><span class="nf">ie-hex-str</span><span class="p">(</span><span class="nv">$color_start</span><span class="p">)</span><span class="o">,</span> <span class="nf">ie-hex-str</span><span class="p">(</span><span class="nv">$color_stop</span><span class="p">)));</span> <span class="c1">// For IE</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">@include</span><span class="nd"> background</span><span class="p">(</span><span class="nf">linear-gradient</span><span class="p">(</span><span class="nv">$color_start</span><span class="o">,</span> <span class="nv">$color_stop</span><span class="p">));</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
background, compass, gradient, sass

SQL

Increment date by 14 days

UPDATE events SET date_starts = DATE_ADD(date_starts,INTERVAL 14 DAY) WHERE event_id = 3;
https://snipt.net/embed/ccc397d6860ef356f43744d5b10c5f14/
/raw/ccc397d6860ef356f43744d5b10c5f14/
ccc397d6860ef356f43744d5b10c5f14
sql
SQL
1
2019-07-14T08:25:20
True
False
False
/api/public/snipt/38558/
increment-date-by-14-days
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">UPDATE</span> <span class="n">events</span> <span class="k">SET</span> <span class="n">date_starts</span> <span class="o">=</span> <span class="n">DATE_ADD</span><span class="p">(</span><span class="n">date_starts</span><span class="p">,</span><span class="nb">INTERVAL</span> <span class="mi">14</span> <span class="k">DAY</span><span class="p">)</span> <span class="k">WHERE</span> <span class="n">event_id</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span> </span></pre></div> </td></tr></table>
date, mysql, sql

MySQL

calculating age from date of birth in MySQL

1
2
3
4
5
-- Version 1:
DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthdate, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthdate, '00-%m-%d')) AS age

-- Version 2:
EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(),birthdate))))+0 AS age
https://snipt.net/embed/ab36407fbbf6db41c66466107242f5e7/
/raw/ab36407fbbf6db41c66466107242f5e7/
ab36407fbbf6db41c66466107242f5e7
mysql
MySQL
5
2019-06-23T13:43:19
True
False
False
/api/public/snipt/37038/
calculating-age-from-date-of-birth-in-mysql
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">-- Version 1:</span> </span><span id="L-2"><a name="L-2"></a><span class="nf">DATE_FORMAT</span><span class="p">(</span><span class="nf">NOW</span><span class="p">(),</span> <span class="s1">&#39;%Y&#39;</span><span class="p">)</span> <span class="o">-</span> <span class="nf">DATE_FORMAT</span><span class="p">(</span><span class="n">birthdate</span><span class="p">,</span> <span class="s1">&#39;%Y&#39;</span><span class="p">)</span> <span class="o">-</span> <span class="p">(</span><span class="nf">DATE_FORMAT</span><span class="p">(</span><span class="nf">NOW</span><span class="p">(),</span> <span class="s1">&#39;00-%m-%d&#39;</span><span class="p">)</span> <span class="o">&lt;</span> <span class="nf">DATE_FORMAT</span><span class="p">(</span><span class="n">birthdate</span><span class="p">,</span> <span class="s1">&#39;00-%m-%d&#39;</span><span class="p">))</span> <span class="k">AS</span> <span class="n">age</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1">-- Version 2:</span> </span><span id="L-5"><a name="L-5"></a><span class="nf">EXTRACT</span><span class="p">(</span><span class="kt">YEAR</span> <span class="k">FROM</span> <span class="p">(</span><span class="nf">FROM_DAYS</span><span class="p">(</span><span class="nf">DATEDIFF</span><span class="p">(</span><span class="nf">NOW</span><span class="p">(),</span><span class="n">birthdate</span><span class="p">))))</span><span class="o">+</span><span class="mi">0</span> <span class="k">AS</span> <span class="n">age</span> </span></pre></div> </td></tr></table>
mysql