chapter31

development in a land far far away…

at the moment

History is not what happened. History is what was written down.

Recently I was just comparing 2 dates (one from a query and the other was now()) using the createODBCDate() and dateCompare() functions.

I was using the createODBCDate() function because I only wanted the ‘date’ part of a date object, not the ‘time’. More than likely I should have been using dateFormat(), but that’s another story :)

I had the following:

The problem was I kept getting -1 returned, meaning that ‘q.DateTimeCreated’ was less than ‘now()’. As ‘q.DateTimeCreated’ was technically created before ‘now()’ (same day but an earlier ‘time’) it is actually less than, but I only wanted to compare the date…not the time. When I dumped both date objects I got:

Looks the same to me…

I think that those date objects actually have the ‘time’ in them as well, they’re just not being displayed on cfdump or cfoutput. This seems strange especially considering there is a createODBCDateTime() function as well.

My fix was to do what I probably should have done in the first place; use dateFormat()

That did the trick!

Now the only thing bothering me is whether the createODBCDate() function actually does return the ‘time’ as well…or was something else the culprit?


Related Pages

4 Responses to “createODBCDate() returns ‘time’ as well?”

  1. I think CreateODBCDate() does have a time index in it - otherwise (I’m guessing here) it wouldn’t be a valid ODBC Date/Time Object?

    if you create a Date/Time field in Access, using Now() as the default, it’ll give you: 05/10/2007 09:54:43.

    Presumably, CreateODBCDate returns:
    05/10/2007 00:00:00 and CreateODBCDateTime will give you 05/10/2007 09:54:43.

    That way they’re both valid for access (ODBC); I’d have a play with plain old CreateDate(), which I believe will just return the “date” part.

    T

    Tom K

  2. I think that’s what was happening Tom, the funny thing was why wasn’t I seeing the time part ‘00:00:00′ when I outputted or dumped the createODBCDate() object?

    createDate() was another option for me, but was more work to pass in each date element (yyyymmdd) etc

    Michael Sharman

  3. We had a similar experience - passing a createodbcdate(now()) value to a function that increments the date based on the day of the week (using dateadd) resulted in a return of a date/time where time was NOT 00:00:00, but the actual time of day. Outputting the passed variable showed no time, while outputting the function result showed the time.

    Dave H

  4. Yeah sounds a bit dodgy Dave, I guess it’s one of those things we just need to keep in mind.

    Makes it harder though when the name of the function seems to go against its behaviour.

    Michael Sharman

Leave a Reply