Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #1248

Re: converting a date to a date but without the time element

From Helmut_Meukel <Helmut_Meukel@bn-hof.invalid>
Newsgroups comp.lang.basic.visual.misc
Subject Re: converting a date to a date but without the time element
Date 2012-06-26 09:57 +0200
Organization HM - Soft Hof
Message-ID <jsbq0p$7s1$1@dont-email.me> (permalink)
References <cfcf1a84-9f99-4937-806e-4a745121e4fb@b21g2000yqn.googlegroups.com> <jqps44$ekj$1@speranza.aioe.org> <6c55a7e2-267d-42a0-ad51-3e17e5833dff@w24g2000vby.googlegroups.com>

Show all headers | View raw


colmkav wrote:
> On Jun 7, 11:26 am, Deanna Earley <dee.ear...@icode.co.uk> wrote:
>> On 07/06/2012 10:07, colmkav wrote:
>> 
>>> How can I take a date provided as a time eg now() and convert it to a
>>> date without the hours, minutes etc?
>>> My issue is that I want to compare this date with that of other dates
>>> but at the moment they arent being evaluated as equal because of the
>>> hours and minutes difference.
>> 
>> I use either DateValue() or Int().
>> I have had unexpected issues with DateValue not working properly with
>> Date values (as it expects a String, and it got day/month backwards) so
>> most of my code now uses Int().
>> 
>
> seem to get overflow error now when I use INT. Not quite sure why.
>
> Previously when I use contextdate = cdate(now()-1) to set my
> contextdate and then use in my SQL query ">= [contextdate]" I get the
> results requested but I want to be able to just select the contextdate
> and not all those after it.

As others already answered CLng() or Int() would do.
If your code *really* looks like
     contextdate = cdate(now()-1)
then why do you use Now() at all?
Have a look at the other related functions Date() and Time() and you'll
see Date() is what you really should use.

To me it looks like you have probably *two* problems:
1) get a contextdate value without the time part
   - solved with either Int(), CLng() or Date() - and
2) compare your contextdate value with the stored values from your
   db field which may or may not contain DateTime values with a time
   part.
If there is a time component in vour db values, one possible solution
would be to use in your SQL query something like
  ">= [contextdate] AND < [contextdate]+1".

This said, you stated with ">= [contextdate]" in your SQL query you get
the requested results plus all those after it.
That's isn't correct. If contextdate contains a time part, you'll miss
all records with this date with lower time values or no time value at
all.

HTH,

Helmut.

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

converting a date to a date but without the time element colmkav <colmjkav@yahoo.co.uk> - 2012-06-07 02:07 -0700
  Re: converting a date to a date but without the time element Deanna Earley <dee.earley@icode.co.uk> - 2012-06-07 10:26 +0100
    Re: converting a date to a date but without the time element colmkav <colmjkav@yahoo.co.uk> - 2012-06-07 03:29 -0700
      Re: converting a date to a date but without the time element Deanna Earley <dee.earley@icode.co.uk> - 2012-06-07 11:43 +0100
        Re: converting a date to a date but without the time element colmkav <colmjkav@yahoo.co.uk> - 2012-06-07 04:50 -0700
          Re: converting a date to a date but without the time element Karl E. Peterson <karl@exmvps.org> - 2012-06-07 11:50 -0700
      Re: converting a date to a date but without the time element Helmut_Meukel <Helmut_Meukel@bn-hof.invalid> - 2012-06-26 09:57 +0200
  Re: converting a date to a date but without the time element Barry Etheridge <purple.mug@googlemail.com> - 2012-06-07 07:49 -0700
    Re: converting a date to a date but without the time element Deanna Earley <dee.earley@icode.co.uk> - 2012-06-07 15:54 +0100
    Re: converting a date to a date but without the time element "DaveO" <djo@dial.pipex.com> - 2012-06-07 16:00 +0100
  Re: converting a date to a date but without the time element ReverendFuzzy <google@msbministries.org> - 2012-07-05 08:51 -0700
  Re: converting a date to a date but without the time element ReverendFuzzy <google@msbministries.org> - 2012-07-05 08:54 -0700
  Re: converting a date to a date but without the time element "Theo Tress" <rbk@online.de> - 2012-07-07 12:13 +0200

csiph-web