Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# date problem.....

Posted on 2003-03-03
Medium Priority
186 Views

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.

0
Question by:raza
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):

struct
{
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

versus:

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.

Kdo
0

## Featured Post

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
###### Suggested Courses
Course of the Month10 days, 13 hours left to enroll