The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » Mortality » Problem in converting birth date CMC from Afghan calendar to Gregorian calendar
Re: Problem in converting birth date CMC from Afghan calendar to Gregorian calendar [message #11880 is a reply to message #11874] Fri, 24 February 2017 01:42 Go to previous messageGo to previous message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 803
Registered: January 2013
Senior Member
Hi Jing,

Below is the conversion function used in CSPro:
  { Convert Persian calendar to Gregorian }
  function dconvert(p_day,p_month,p_year);  { Assume for all years that the vernal equinox is at March 21st }
    xtemp = 1;
    if validyr(p_year) & p_month in 1:12 then

      g_year = p_year + 621;                                                       { 1;Hammal - 31 days (March-April)                   }
      if !(p_day in 1:31) then                                                     { 2;Saur - 31 days (April-May)                       }
        p_day = 15;                                                                { 3;Jauza - 31 days (May-June)                       }
      endif;                                                                       { 4;Saratan - 31 days (June-July)                    }
      { number of days since start Persian year }                                  { 5;Asad - 31 days (July-August)                     }
      box p_month => days;                                                         { 6;Sonbola - 31 days (August-September)             }
            1-6   => (p_month-1) * 31 + p_day;                                     { 7;Mizan - 30 days (September - October)            }
                  => 186 + (p_month-7) * 30 + p_day;                               { 8;Aqrab - 30 days (October-November)               }
      endbox;                                                                      { 9;Qaus - 30 days (Novemebr - December)             }
      { Days between vernal equinox and Jan. 1st }                                 { 10;Jadi - 30 days (December - January)             }
      equinox = 80;                                                                { 11;Dalw - 30 days (January-February)               }
      { number of days Gregorian is under way }                                    { 12;Hut - 29/30 days (February-March)               }
      tdays = equinox + days;
      leapyear = (g_year%4 = 0);
      if !leapyear then
        if tdays > 365 then
          tdays = tdays - 365;
          g_year = g_year + 1;
        endif;
      else
        if tdays > 366 then
          tdays = tdays - 366;
          g_year = g_year + 1;
        endif;
      endif;
      if leapyear & tdays >= 60 then tdays = tdays - 1 endif;

      { Determine Gregorian month }
      box tdays => g_month;
         <=  31 =>  1;
         <=  59 =>  2;
         <=  90 =>  3;
         <= 120 =>  4;
         <= 151 =>  5;
         <= 181 =>  6;
         <= 212 =>  7;
         <= 243 =>  8;
         <= 273 =>  9;
         <= 304 => 10;
         <= 334 => 11;
                => 12;
      endbox;

      { And the day in the month }
      box         tdays => g_day;
         <= 31 => tdays;
        <=  59 => tdays - 31;
        <=  90 => tdays - 59;
        <= 120 => tdays - 90;
        <= 151 => tdays - 120;
        <= 181 => tdays - 151;
        <= 212 => tdays - 181;
        <= 243 => tdays - 212;
        <= 273 => tdays - 243;
        <= 304 => tdays - 273;
        <= 334 => tdays - 304;
               => tdays - 334;
      endbox;
    else
      g_day = p_day;                { Cannot determine }
      if validyr(p_year) then
        g_year  = p_year + 621;     { most likely; first 9 months }
        g_month = p_month;          { DK/missing }
      else
        if p_month in 1:12 then
          g_year = p_year;          { DK/missing }
          box p_month => g_month;
                 1-9  => p_month + 3;  { most likely; 21 days out 31 }
                      => p_month - 9;
          endbox;
        else
          g_year  = p_year;    { DK/missing }
          g_month = p_month;   { DK/missing }
        endif;
      endif;
    endif;
    if g_year = 2011 then
      g_year = 2010;
      g_month = 12;
    endif;

    dconvert = xtemp;
    {errmsg("In:%d-%d-%d and out: %d-%d-%d",p_day,p_month,p_year,g_day,g_month,g_year); }
  end;
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Maternal Mortality Ratio
Next Topic: INFANT AND CHILD MORTALITY
Goto Forum:
  


Current Time: Mon Dec 2 09:35:58 Coordinated Universal Time 2024