Skip to main content

The formula I used to build the Bazi Calculator by Master Ben

Step 1: Year Pillar

Find the Heavenly Stem of the Year (天干)

  • Year stem = Formula: (Year – 4) mod 10
    • Correspondence:
0 - 甲 (Jia) 
1 - 乙 (Yi)    
2 - 丙 (Bing) 
3 - 丁 (Ding) 
4 - 戊 (Wu) 
5 - 己 (Ji)  
6 - 庚 (Geng)  
7 - 辛 (Xin)  
8 - 壬 (Ren)  
9 - 癸 (Gui)   

Find the Earthly Branch of the Year (地支)

  • Year branch = Formula: (Year – 4) mod 12
    • Correspondence:
0  - 子 (Zi) 
1  - 丑 (Chou)
2  - 寅 (Yin) 
3  - 卯 (Mao) 
4  - 辰 (Chen)
5  - 巳 (Si) 
6  - 午 (Wu)   
7  - 未 (Wei) 
8  - 申 (Shen)
9  - 酉 (You) 
10 - 戌 (Xu)
11 - 亥 (Hai)  

Step 2: Month Pillar

  • The Heavenly Stem of the Month is determined by:
    • monthStem = (  tigerStart +  tigerMonth )mod 10
      • tigerStart = ((yearStemIndex)mod5 +1)x 2) 
      • tigerMonth = (lunarMonth-1)-2
        • If tigerMonth < 0
          • tigerMonth = tigerMonth+12
        • lunarMonth-1 (to Make lunarMonth 0 adjusted))
        • 0 adjusted system lets us use mathematical formula MOD
  • Tiger 5
    • 2,4,6,8,0 because we using a 0 system instead of a 1 system.
0 - 甲 (Jia)  5 - 己 (Ji)   Tiger2 - 丙 (Bing) <-Start at bing if jia or ji
1 - 乙 (Yi)   6 - 庚 (Geng) Tiger4 - 戊 (Wu)  <-Start at wu if yi or Geng
2 - 丙 (Bing) 7 - 辛 (Xin)  Tiger6 - 庚 (Geng)
3 - 丁 (Ding) 8 - 壬 (Ren)  Tiger8 - 壬 (Ren)
4 - 戊 (Wu)   9 - 癸 (Gui)  Tiger0 - 甲 (Jia)
turn this into formula tigerStart = ((yearStem)mod5 +1)x 2) = tigerStart

 The Earthly Branch of the Month is fixed:

AI provided
Dec 7 – Jan 5 - 子 (Zi)   
Jan 6 – Feb 3 - 丑 (Chou) 
Feb 4 – Mar 5 - 寅 (Yin)
Mar 6 – Apr 4 - 卯 (Mao) 
Apr 5 – May 5 - 辰 (Chen) 
May 6 – Jun 5 - 巳 (Si)
Jun 6 – Jul 6 - 午 (Wu)  
Jul 7 – Aug 7 - 未 (Wei) 
Aug 8 – Sep 7 - 申 (Shen)
Sep 8 – Oct 7 - 酉 (You) 
Oct 8 – Nov 6 - 戌 (Xu)  
Nov 7 – Dec 6 - 亥 (Hai)

Popular calculators (we are following this)
Dec 8 – Jan 4  - 子 (Zi)   -1  
Jan 5 – Feb 3  - 丑 (Chou) -2
Feb 4 – Mar 5  - 寅 (Yin)  -3
Mar 6 – Apr 4  - 卯 (Mao)  -4
Apr 5 – May 4  - 辰 (Chen) -5
May 5 – Jun 4  - 巳 (Si)   -6
Jun 5 – Jul 6  - 午 (Wu)   -7
Jul 7 – Aug 7  - 未 (Wei)  -8
Aug 8 – Sep 7  - 申 (Shen) -9
Sep 8 – Oct 7  - 酉 (You)  -10
Oct 8 – Nov 7  - 戌 (Xu)   -11
Nov 8 – Dec 7  - 亥 (Hai)  -12

Step 3: Day Pillar

  • Base Date: February 4, 1924 (start of a known Jia-Zi day, 60-day cycle)
  • Days between birthdate and base date:
    • day stem     = (Birthdate – Base Date -1 ) mod 10 
    • day branch = (Birthdate – Base Date +1 ) mod 12 

Step 4: Determine the Hour Pillar

  • Heavenly Stem of the Hour
    • hourStem = ( ( dayStemIndex * 2 ) + hourBranchIndex ) mod 10;
    • IF hourBranchIndex == 0 (Zi) and time is 23:00-23:59
      • dayStemIndex = dayStemIndex_tomorrow
      • dayStemIndex_tomorrow = (Birthdate – Base Date) mod 10 
      • Day starts and ends at 11PM. So if 11PM-11:59PM need to adjust to calculate based on the next day.
  • Earthly Branch of the Hour
    • Correspondence:
23:00-00:59 - 子 (Zi)  
01:00-02:59 - 丑 (Chou)
03:00-04:59 - 寅 (Yin)
05:00-06:59 - 卯 (Mao)
07:00-08:59 - 辰 (Chen)
09:00-10:59 - 巳 (Si)
11:00-12:59 - 午 (Wu) 
13:00-14:59 - 未 (Wei)
15:00-16:59 - 申 (Shen)
17:00-18:59 - 酉 (You)
19:00-20:59 - 戌 (Xu)
21:00-22:59 - 亥 (Hai)

Leave a Reply