First off - please do not post code as a comment. Use the green Improve Question button/link to paste your code as a code block in your original question. When you paste you will be asked how to format your text - pick Java code block. Then delete your comment if you can.

Now on to your problem. You state you don't want to use built-in functions or classes. Why that would be is beyond me. Any significant coding you do will use those objects as a matter of course. Using them here will teach how to use them which is useful in and of itself.

Regardless of my opinion, to solve your problem: Since you're dealing with dates only, I will assume you want a difference in days. I would probably convert both dates to a number in the same context. What I mean by that is to convert each one to something like the number of days since a common start date. That could be January 1, 2000 or January 1, 1900. Just pick a base date that is earlier than what either can be. Subtract the 2 values and voila you have the difference in days.

But, you say, all I've done is change taking the difference between 2 dates to that of taking the difference twice - between each given date and the base date. Perhaps so, but what really happens is now you have a common function to get a base value from any date. That function may be somewhat complex, especially if leap years need to be taken into account, but the rest of your code that needs date differences will be simple to write, read and understand.

15,997,667 members

import java.util.Scanner;

public class days2Dates {

public static void main(String[] args) {

Scanner kb = new Scanner(System.in);

System.out.println("M and D");

int m = kb.nextInt();

int d = kb.nextInt();

System.out.println("M2 and D2");

int m2 = kb.nextInt();

int d2 = kb.nextInt();

kb.close();

int days = 0;

for(int i = m; i<=m2; i++) {

if (i % 2 != 0 || i == 8 || i == 10 || i == 12) {

if (i != 9 && i != 11 && i != m2) {

days = days + (31-d);

}

if (i == 9 && i != m2) {

if (d2<31 && d2>0 && m != 9){

days = days + (d2);

}

if (d2 > 31 && m != 9) {

days = days + 30;

}

if (i == 9 && i != m) {

days = days + (30-d);

}

if (i == m2 && m2 == m) {

days = days + (d2-d);

}

}

if (i == m2 && i != m && i!=9 && i != 11) {

days = days + (31-d);

}

if (i == m2 && m2 == m) {

days = days + (d2-d);

}

if (i == 11 && i != m2) {

if (d2<31 && d2>0 && m != 11){

days = days + d2;

}

if (d2 > 31 && m != 11) {

days = days + 30;

}

if ()

}

}

else if (i % 2 == 0) {

if (i != 2 && i != 8 && i != 10 && i != 12 && i != m) {

if (d < 31 && d > 0){

days = days + d;

}

else {

days = days + 30;

}

}

if (i == 8) {

days = days + d;

}

if (i == 10) {

days = days + d;

}

if (i == 12) {

days = days + d;

}

if (i == m && i != 12){

days = days + d;

}

else if (i == 2){

if (d > 0 && d < 29) {

days = days + d;

}

else {

days = days + 28;

}

}

}

}

System.out.println(days);

//find the number of days from 01/01/2023 till m/d/2023

}

}