Saturday, December 16, 2017

Broken Korean Text Fix

Due to a unique character encoding widely used for Korean text in Korea, you may run into broken, unrecognizable text when opening a file (txt, smi, hwp, doc, etc) created on the Korean Windows platform.

Use Notepad++ to fix such broken Korean text. Notepad++ is an open-source software freely available to download (https://notepad-plus-plus.org). It is available for Windows only.

  1. Download and install Notepad++ on Windows.
  2. Open the original text in another text editor like the "Notepad".
  3. Copy all broken Korean text.
  4. On Notepad++, start a new blank file. 
    1. Go to Menu --> Encoding --> Character Sets --> Western Europe --> Windows 1252.
    2. Paste the copied broken Korean text on Notepad++'s new file.
    3. Go to Menu --> Encoding --> Encode in UTF-8
    4. When prompted to save the file, go ahead and save it.
    5. As the file is saved, the broken Korean text are fixed.


Wednesday, December 6, 2017

Age calculation based on today's date and birthday

To calculate the exact age based on today's date and birthday, it might be a little tricky to implement it in SQL. Below is one way to do it.
declare @BirthDate datetime = '12/1/2016'
declare @Today datetime = DateAdd(dd, DateDiff(dd, 0, getdate()), 0)

declare @age int = 
  ( CONVERT(int,CONVERT(char(8),@Today,112)) - CONVERT(char(8), @BirthDate, 112)) /10000

select @age 
/* returns 1 if today's date is 12/1/2017. */
/* returns 0 if today's date is 12/2/2017. */