Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to restrict previous dates to current date #25

Open
nepnesomao opened this issue Aug 4, 2015 · 1 comment
Open

How to restrict previous dates to current date #25

nepnesomao opened this issue Aug 4, 2015 · 1 comment

Comments

@nepnesomao
Copy link

Hi,

I need to restrict previous dates to current date.
How can i make to this?

Sorry my poor English.

@MinteFino
Copy link

To restrict users from selecting previous dates and only allow selection of the current date or future dates in C programming, you can modify your code as follows. Here, I'll provide a console-based example that checks for valid date selection:

#include <stdio.h>
#include <time.h>

#define NUM_DATES 31 // Assuming 31 date cells

int main() {
int selectedDates[NUM_DATES] = {0}; // Initialize an array to track selected dates
int currentDate = 0; // Initialize to no date selected
int selectedDate;

// Get the current date
time_t t;
struct tm *tm_info;
time(&t);
tm_info = localtime(&t);
currentDate = tm_info->tm_mday; // Current day of the month

printf("Today's date is the %dth\n", currentDate);

// Simulate user selecting a date (for example, the 10th)
selectedDate = 10;

// Check if the selected date is valid
if (selectedDate >= currentDate) {
    selectedDates[selectedDate] = 1; // Mark the selected date in the array
} else {
    printf("Invalid selection. You can only select today's date or a future date.\n");
}

// Display date cells and change colors based on selection
for (int i = 1; i <= NUM_DATES; i++) {
    if (selectedDates[i] == 1) {
        printf("\x1b[31m"); // Change text color to red (you can customize this)
    }

    printf("%2d ", i);

    if (selectedDates[i] == 1) {
        printf("\x1b[0m"); // Reset text color to default
    }
}

return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants