---
title: "Convert date from BS to AD"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:struct-bs-to-ad"
source: https://www.bctengineer.com/q/semester_1/computer_programming/struct-bs-to-ad
site: BCT Engineering
---

# Convert date from BS to AD

Computer Programming · Chapter 8: Structures

- Asked in: 2067 Asoj, 6 marks; 2070 Chaitra, 5 marks (asked 2 times)
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/struct-bs-to-ad
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

Write a C program to convert date in B.S. to A.D. using structure. (Pass the structure to the function that returns the result to convert the date (in format YY/MM/DD) in B.S. to A.D. / use the date difference of current date.)

## Short answer

Count the days between the given BS date and a reference (2080/01/01 BS = 2023/04/14 AD) using a table of BS month lengths, then add those days to the reference AD date. Example: 2081/06/15 BS converts to 2024/10/01 AD.

## Answer

**Idea (date difference method).** A BS date is converted by counting the days between a known reference date and the given date, then adding that many days to the matching AD reference date. The reference used here is 2080/01/01 BS = 2023/04/14 AD. The number of days in a BS month is not fixed (29 to 32) and changes from year to year, so a table of month lengths is needed. To keep the program short, the table below covers only 2080 and 2081 BS; a full converter needs the table for every year. The program therefore checks the input and rejects any date outside the table.

Steps:
1. A structure `date` holds year, month and day.
2. `main()` reads the BS date and checks that the year is in the table and that the month and day are valid.
3. `bsToAd()` receives the `date` structure, counts the days from 2080/01/01 BS using the table, and adds them one by one to 2023/04/14 AD (taking care of month ends and leap years).
4. The function returns the AD date as a structure, which `main()` displays.

```c
#include <stdio.h>

struct date {
    int year, month, day;
};

/* days in each BS month; table available for 2080 and 2081 only */
int bsDays[2][12] = {
    {31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30},   /* 2080 */
    {31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30}    /* 2081 */
};

int adDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int isLeap(int y)
{
    return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
}

/* 2080/01/01 BS = 2023/04/14 AD */
struct date bsToAd(struct date bs)
{
    struct date ad = {2023, 4, 14};
    int diff = 0;                               /* days since 2080/01/01 */

    for (int y = 2080; y < bs.year; y++)
        for (int m = 0; m < 12; m++)
            diff += bsDays[y - 2080][m];
    for (int m = 0; m < bs.month - 1; m++)
        diff += bsDays[bs.year - 2080][m];
    diff += bs.day - 1;

    while (diff > 0) {                          /* add days to the AD date */
        int dim = adDays[ad.month - 1] + (ad.month == 2 && isLeap(ad.year));
        if (ad.day < dim)
            ad.day++;
        else {
            ad.day = 1;
            if (++ad.month > 12) {
                ad.month = 1;
                ad.year++;
            }
        }
        diff--;
    }
    return ad;
}

int main(void)
{
    struct date bs, ad;
    printf("Enter BS date (YYYY/MM/DD, 2080-2081): ");
    if (scanf("%d/%d/%d", &bs.year, &bs.month, &bs.day) != 3
        || bs.year < 2080 || bs.year > 2081
        || bs.month < 1 || bs.month > 12
        || bs.day < 1 || bs.day > bsDays[bs.year - 2080][bs.month - 1]) {
        printf("Invalid date or year outside the table\n");
        return 1;
    }
    ad = bsToAd(bs);
    printf("AD date = %04d/%02d/%02d\n", ad.year, ad.month, ad.day);
    return 0;
}
```

**Sample run**

Input: `2081/06/15`

```text
Enter BS date (YYYY/MM/DD, 2080-2081): AD date = 2024/10/01
```

2081/06/15 BS (15 Ashwin) corresponds to 1 October 2024 AD. An input such as `2082/01/01` prints `Invalid date or year outside the table`; to support it, add that year's row to `bsDays`.

(The quick approximate rule used in some textbooks is: AD year = BS year − 57 from 1 Baisakh (about 13/14 April) to the end of December, and BS year − 56 from January to mid-April. It does not give the exact day.)

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What method is used to convert BS to AD?
   A. Subtract 57 from the BS month
   B. Count days from the reference 2080/01/01 BS and add them to 2023/04/14 AD
   C. Multiply the BS year by 365
   D. Look up the date on the internet
   Answer: B. The date-difference method adds the day count to the AD reference. (Key point: Method)

2. Why is a table of BS month lengths needed?
   A. BS months are always 30 days
   B. AD months have no fixed length
   C. BS months have 29 to 32 days and differ every year
   D. To store the AD year
   Answer: C. No formula gives BS month lengths, so a table is used. (Key point: Month table)

3. What is the reference pair used?
   A. 2000/01/01 BS = 1943/04/14 AD
   B. 2080/01/01 BS = 2023/01/01 AD
   C. 2081/01/01 BS = 2023/04/14 AD
   D. 2080/01/01 BS = 2023/04/14 AD
   Answer: D. This pair anchors the day count. (Key point: Reference date)

4. What must be handled when adding days to the AD date?
   A. Month ends and leap years (February length)
   B. Only the year
   C. Only weekdays
   D. Nothing special
   Answer: A. The loop checks days in month using the leap year rule. (Key point: Adding days to AD)

5. How does the function return the AD date?
   A. It prints and returns void
   B. It returns a struct date, displayed by main()
   C. It returns an int
   D. It changes a global string
   Answer: B. bsToAd takes a date structure and returns another one. (Key point: Structure use)

6. What is the quick approximate rule mentioned for BS to AD year?
   A. AD year = BS year + 57
   B. AD year = BS year - 100
   C. AD year = BS year - 57 (not exact for all dates)
   D. AD year = BS year / 57
   Answer: C. It is only approximate, around 13/14 April for 1 Baisakh. (Key point: Approximate rule)

## Related in Computer Programming

- [College records with nested date structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-college-estdate) — Computer Programming, chapter 8
- [Height difference using nested structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-height-feet-inches) — Computer Programming, chapter 8
- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Declaration vs definition; C program structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adeclaration-definition-structure-of-c) — Computer Programming, chapter 3
- [Sending structure members to a function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-members-to-function) — Computer Programming, chapter 8
- [Pass array; transpose 3×3 matrix](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-array-transpose-3x3) — Computer Programming, chapter 7

## Related in other subjects

- [Protected specifier; student/test/result program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprotected-three-class-program) — Object Oriented Programming, chapter 6
- [JavaScript DOM and date-time function](https://www.bctengineer.com/question.md?key=semester_7%2Fweb_technology%3Ajavascript-dom-date-time) — Web Technology, chapter 4
- [Namespace with pass by reference program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Anamespace-pass-by-ref-program) — Object Oriented Programming, chapter 2
- [Transfer function of RC low-pass filter](https://www.bctengineer.com/question.md?key=semester_4%2Fsignals_and_systems%3Arc-lowpass-transfer-function) — Signals and Systems, chapter 5, asked 2×
