date problem.....

Posted on 2003-03-03
Medium Priority
Last Modified: 2010-04-15

date formate :YYYY-MM-DD HH:MM:SS.T

I have two date-time. Start_Date-time and End_Date-time. I need to find out if current date-time is fall in between start and End date-time for an executeing a task.

what is the best way to do it.

Question by:raza
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 46

Accepted Solution

Kent Olsen earned 200 total points
ID: 8060606

If the date-time values are strings you can just do a compare with strcmp().  The order of the fields is most-significant to least-signficant so a direct compare will work fine.

If you're dealing with "struct"s you have to know the architecture of the machine that you're using.  Big-endian and Little-endian machines store integer data left-to-right and right-to-left, respectfully.

This means that the data in two structures is not necessarily the same when put in memory.  (The computer will convert the data as necessary whenever read-to or written-from a register so you will always "see" the value that you intended.)

Consider (pseudo code):

  int A;
  int B;

struct1.A = 1;
struct1.B = 2;
struct2.A = 3;
struct2.B = 4;

In memory one architecture will store this as:

00 01 00 02
00 03 00 04

another architecture will store this as:

01 00 02 00
03 00 04 00

In both of these cases, using memcmp() to determine which value is smaller will give the correct result.  But what happens with other values?

struct1.A = 1;
struct1.B = 2;
struct2.A = 256;
struct2.B = 258;

Now we get:

00 01 00 02
01 00 01 02


01 00 02 00
00 01 02 01

Because of the "byte swapping" that occurs when register values are stored to memory, we get values that MUST be compared in registers to give an accurate comparison.

Therefore, you will have to test each field individually, or convert the date-time values to a strings and compare them.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question