Check current time (without date) is between two times in C

Check current time (without date) is between two times in C

Content Index :

Check current time (without date) is between two times in C
Tag : c , By : RyanMcG
Date : November 28 2020, 11:01 PM

To fix this issue A shortest comparison solution consists to convert all string-timestamp to time_t value.
struct tm tmVar;
time_t t_on_time, t_off_time, t_curr_time;

    memset(&tmVar, 0, sizeof(tmVar));    
    if(sscanf(on_time, "%d:%d:%d", &tmVar.tm_hour,  &tmVar.tm_min,  &tmVar.tm_sec)==3) {
        t_on_time = mktime(&tmVar);
    memset(&tmVar, 0, sizeof(tmVar)); 
    if(sscanf(off_time, "%d:%d:%d", &tmVar.tm_hour,  &tmVar.tm_min,  &tmVar.tm_sec)==3) {
        t_off_time = mktime(&tmVar);
    memset(&tmVar, 0, sizeof(tmVar)); 
    if(sscanf(CURTIME(), "%d:%d:%d", &tmVar.tm_hour,  &tmVar.tm_min,  &tmVar.tm_sec)==3) {
        t_curr_time = mktime(&tmVar);
if (((t_on_time <= t_off_time) && (t_curr_time >= t_on_time) && (t_curr_time <= t_off_time)) ||
 ((t_off_time < t_on_time) && ((t_curr_time <= t_off_time) || (t_curr_time >= t_on_time))) {
    // To do something

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

ios- Check whether current time is between two times or not

Tag : ios , By : Chandra P Singh
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I want to check whether the current time is between two time or not. , Try this
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
NSInteger currentHour = [components hour];
NSInteger currentMinute = [components minute];
NSInteger currentSecond = [components second];

if (currentHour < 7 || (currentHour > 21 || currentHour == 21 && (currentMinute > 0 || currentSecond > 0))) {
    // Do Something

How to check if the Current Time is in between Two Given TImes?

Tag : jquery , By : agjimenez
Date : March 29 2020, 07:55 AM
I wish this help you I have got startTime and endTime and current_time , how to check if the current time is in between these two times or not ?? , Try this code.. This code will convert 12 hr time to 24 hr time.
    var startTime = '12:27 PM';
    var endTime = '12:36 PM';

    var curr_time = getval();

    if (get24Hr(curr_time) > get24Hr(startTime) && get24Hr(curr_time) < get24Hr(endTime)) {
      //in between these two times
    } else {

    function get24Hr(time){
      var hours = Number(time.match(/^(\d+)/)[1]);
      var AMPM = time.match(/\s(.*)$/)[1];
      if(AMPM == "PM" && hours<12) hours = hours+12;
      if(AMPM == "AM" && hours==12) hours = hours-12;

      var minutes = Number(time.match(/:(\d+)/)[1]);
      hours = hours*100+minutes;
      console.log(time +" - "+hours);
      return hours;

    function getval() {
     var currentTime = new Date()
     var hours = currentTime.getHours()
     var minutes = currentTime.getMinutes()

     if (minutes < 10) minutes = "0" + minutes;

     var suffix = "AM";
     if (hours >= 12) {
        suffix = "PM";
        hours = hours - 12;
     if (hours == 0) {
        hours = 12;
     var current_time = hours + ":" + minutes + " " + suffix;

     return current_time;


how to check current date time is in between given date times in iOS?

Tag : ios , By : CM.
Date : March 29 2020, 07:55 AM
I wish this help you I'm not sure how you are calculating your startDate and end Date, but to simply calculate if your current date is in between two dates or not, you can do this:
Get the dates:
NSString *startingDate = @"01-06-2016 20:09:47 PM";
NSString *endingDate = @"08-06-2016 20:09:47 PM";

NSDateFormatter *startForm=[[NSDateFormatter alloc]init];
[startForm setDateFormat:@"dd-MM-yyyy HH:mm:ss a"];
NSDate *startDate = [startForm dateFromString:startingDate];
NSDate *endDate = [startForm dateFromString:endingDate];
 case A - (startDateIsOld && !endDateIsOld)
 case B-  (!startDateIsOld && endDateIsOld)
- (BOOL)isDate:(NSDate *)date inRangeFirstDate:(NSDate *)firstDate lastDate:(NSDate *)lastDate {

    BOOL startDateIsOld = false;
    BOOL endDateIsOld = false;

    if ([date compare:firstDate]==NSOrderedAscending) {
    NSLog(@"first date is after current date");
    if ([date compare:lastDate]==NSOrderedDescending){
    NSLog(@"last date is before current date");
    if ([date compare:firstDate]==NSOrderedDescending) {
    NSLog(@"first date is before current date");
    if ([date compare:lastDate]==NSOrderedAscending){
    NSLog(@"last date is after current date");
    if ((startDateIsOld && !endDateIsOld) || (!startDateIsOld && endDateIsOld) ) {
     NSLog(@"date is in range");
    return YES;
    return NO;
 if ((([date compare:firstDate]==NSOrderedDescending) && ([date compare:lastDate]==NSOrderedAscending)) || (([date compare:firstDate]==NSOrderedAscending) && ([date compare:lastDate]==NSOrderedDescending))) {
    NSLog(@"date is in range");
    return YES;

How can I check if the current date/time is past a set date/time in variable time zones?

Tag : php , By : user185751
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Using DateTime, you can specify a time and time zone then compare to the current time:
$date = new DateTime('2017-05-05 07:00:00', new DateTimeZone('TimezoneID'));
return ($date->getTimestamp() < time());

Check if the current time is between other times

Tag : objective-c , By : Jay Crockett
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • windows C system call with spaces in command
  • FFmpeg C API documentation/tutorial
  • Thread scheduling Round Robin / scheduling dispatch
  • Define integer ranges in C
  • feof() in C file handling
  • How to check for signed integer overflow in C without undefined behaviour?
  • Display processes that access a folder
  • How to printf a time_t variable as a floating point number?
  • Parenthesis operator in C. What is the effect in the following code
  • Is there table with timing(cost) of C functions?
  • How can I access a global pointer outside of a C function?
  • Are fopen/fread/fgets PID-safe in C?
  • How can multiple variables be passed to a function cleanly in C?
  • How to use pthread_atfork() and pthread_once() to reinitialize mutexes in child processes
  • Find function call in a list of binaries
  • How to return a single variable from a CUDA kernel function?
  • How to get number of cores in Win32?
  • Handling aces and finding a segfault in a blackjack program
  • function prototype declarations
  • How to convert from Hex to Decimal using only Integers in C
  • How to parse from char array using yacc?
  • I can not work with linked list inside linked list
  • Finding the index of largest number
  • Decompose a number to product of prime numbers and print it like 18=2*3^2
  • programming EXACT timer which calles a function in c language every x seconds
  • Combining macros generate errors
  • Why am I not getting error when I store values of different types in an array in C language?
  • What is the purpose of the base case dp[0] = -1 of this DP array in the palindromic partitions problem?
  • Having function choose largest number of given ones
  • Data structures layout
  • How to retrieve probuf from C library
  • Printf float number in hexadecimal format returns random vlaue
  • Memory allocation in C from 1 to N
  • Emit signal from separate thread in glib/gtk
  • How to fix Valgrind "Conditional Jump..." error
  • The text to be printed is being printed on the command line rather than print space while using fork on terminal
  • Deleting an element from an array of structures
  • How to read time stamp data from text file using C code?
  • I can't understand this code? Is it normal or I'm not ready?
  • GTK character count vs byte index
  • Summing up integers in an array and storing the result in an array
  • JITtting with limited knowledge of the target architecture
  • Why does global pointers behave erratically in this function?
  • Write a basic half pyramid pattern program
  • Read memory in C
  • void affecting output of the program
  • How to limit scanf while reading input from file
  • Why does the C runtime not call my exit()?
  • Can anyone say why the array is not changed when passed to a function
  • Integer overflow (Smallest file size that will make the integer in program become negative in bits)
  • Array of pointers to strings(base type of pointers)
  • Is there any way to limit integer datatype value range
  • How to print 2-byte unicode characters
  • The execution of open when using O_CREAT
  • Parsing Command Line Arguments for Shell
  • Undefined length of character arrays
  • Do condition formats in if/else if statements have to match in C?
  • Generate ordered passwords for brute forcing in C
  • Problems with pointer into structure
  • Why does this C program print output "10" irrespective of the for loop?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com