Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime Field

Status
Not open for further replies.

John Stephen

Programmer
Jan 29, 2019
50
AU
Hi All
VFP9
I wish to Browse a list excluding Datetimes prior to the current DateTime()
Datetime field Closedate
BROWSE FOR Closedate>=Datetime()
Gives me all dates from today forwards but seems to ignore the time. I would like to Browse all records >= the current Date and time
HOURS SET to 24
Is there a simple way of doing this
Thanks Guys
Cheers
John
 
I think you understand tomorrow morning is after todays afternoon. So, you don't get two comparisons for one. But you can make two conditions from this:

BROWSE FOR Closedate>=Datetime() AND TTOC(Closedate,2)>= Time()

Having hours set to 24 is indeed a necessary setting, as Time() is giving the time in 24 hour format hh:mm:ss without AM/PM. You could of course also use TTOC(Datetime(),2) instead of Time(), but that's just details.

I don't see a good use for that, as you would get only sparsely any data when you query that in the eveneing, but you might be interested in about the same timespan of the next few days only, then you could use Between() for both the Datetime() to limit data to a week and for the allowed clock time span to go from current time +/- 2 hourse, for example.

Chriss
 
Here's the Visual FreePro code for decoding an 8-byte datetime value from disk:

Code:
// C/C++ code:
// Note:  u32 = uint32_t, s32 = int32_t, f32 = float
void iiDateMath_get_YyyyMmDd_from_julian  (u32  tnJulianDayNumber, u32* year, u32* month, u32* day);
void iiDateMath_get_HhMmSsMss_from_seconds(f32 tfSeconds, u32* hour, u32* minute, u32* second, s32* millisecond);

// Note:  General form on disk:
struct SDateTime
{
    s32    julian;       // Julian day number
    f32    seconds;      // Seconds elapsed since midnight
};


//////////
//
// Computes the day, month, and year from a julian day number.
//
// Taken from:
//      [URL unfurl="true"]http://stason.org/TULARC/society/calendars/2-15-1-Is-there-a-formula-for-calculating-the-Julian-day-nu.html[/URL]
//
// Returns:
//      year        -- The year
//      month       -- The month
//      day         -- The day
//
//////
    void iiDateMath_get_YyyyMmDd_from_julian(u32 tnJulianDayNumber, u32* year, u32* month, u32* day)
    {
        u32 a, b, c, d, e, m;

        // Validate the range
        tnJulianDayNumber = min(max(tnJulianDayNumber, (u32)2299161/*Oct.15.1582*/), (u32)5373484/*Dec.31.9999*/);

        // Compute
        a       = tnJulianDayNumber + 32044;
        b       = ((4 * a) + 3) / 146097;
        c       = a - ((b * 146097) / 4);
        d       = ((4 * c) + 3) / 1461;
        e       = c - ((1461 * d) / 4);
        m       = ((5 * e) + 2) / 153;
        *day    = e - (((153 * m) + 2) / 5) + 1;
        *month  = m + 3 - (12 * (m / 10));
        *year   = (b * 100) + d - 4800 + (m / 10);
    }

//////////
//
// Takes the number of seconds elapsed since midnight and computes the time.
//
//////
    void iiDateMath_get_HhMmSsMss_from_seconds(f32 tfSeconds, u32* hour, u32* minute, u32* second, s32* millisecond)
    {
        s32 lnMillisecond;
        u32 lnHour, lnMinute, lnSecond;


        // Make sure our parameters exist
        if (!hour)          hour        = &lnHour;
        if (!minute)        minute      = &lnMinute;
        if (!second)        second      = &lnSecond;
        if (!millisecond)   millisecond = &lnMillisecond;

        // Compute hour
        *hour           = (u32)tfSeconds / (60 * 60);
        tfSeconds       = tfSeconds - (f32)(*hour * 60 * 60);

        // Compute minute
        *minute         = (u32)tfSeconds / 60;
        tfSeconds       = tfSeconds - (f32)(*minute * 60);

        // Compute seconds
        *second         = (u32)tfSeconds;
        tfSeconds       = tfSeconds - (f32)*second;

        // Compute milliseconds
        *millisecond    = (s32)(tfSeconds * 999.0);
    }

Datetime values are physically stored on disk as two 4-byte quantities. The first 4-bytes is the julian day number. The second 4-bytes is the SECONDS() equivalent 32-bit floating point value. The above functions will decode them.

--
Rick C. Hodgin
 
I just found the original code I had developed relating to this when I was looking for code to process the SAVE TO memory variable content, thinking that might assist someone in another thread who's looking for a way to see the members of an object in natural order.

See Original SaveToParser on tek-tips.

--
Rick C. Hodgin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top