Results 1 to 4 of 4
  1. #1
    kkrishna is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    12

    How to build a datetime column ....


    Hi All,

    I have an Access 2007 database with two columns - RefYear and RefMonth - with datatype as Integer. I want to add a column to this table of datatype DateTime, in the format 'RefYear/RefMonth'.

    That is, if the RefMonth is 6 (not 06) and RefYear is 2010, I want the value in the new column to be '2010/6' and recognized as DateTime format.

    I am finding it difficult to write queries with BETWEEN .. AND with integer values for RefYear and RefMonth.

    Date is not important, but if the format requires it, the column value can be modified to '2010/6/1'.

    Will someone please advise me how to do it?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use the DateSerial() function with your two fields plus a day to build a date. In your query:

    WHERE DateSerial(...) Between ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kkrishna is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    12
    Thanks for the reply.

    In fact I found solution by adding a DateTime data type column to the existing table. I included a new column manually (I could have done it by the ALTER TABLE .... statement also) name DateCol. Then I ran the following query:

    UPDATE TblPerformanceData
    SET DatCol = RefMonth & '/1' & RefYear

    This has populated the new column with the dates.

    Then I added the part for the existing query:

    WHERE pd.DateCol BETWEEN (#12/1/2009#) AND (##11/1/2010#)

    The dates are now hard-coded; but I plan to set up a dialog box for them.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The downside to a field is that it is a calculated field, which you generally shouldn't save. In this case, you need to account for every new or updated record to make sure that field stays current (like if a user changes the month value for whatever reason).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help to build a ranking
    By chorbi26 in forum Access
    Replies: 0
    Last Post: 12-20-2010, 12:47 PM
  2. array of DateTime in design view
    By lorenb in forum Access
    Replies: 3
    Last Post: 10-22-2010, 09:54 AM
  3. Hellp with Query Build
    By zarfx4 in forum Queries
    Replies: 0
    Last Post: 05-28-2009, 08:21 AM
  4. Replies: 1
    Last Post: 03-04-2009, 10:13 PM
  5. HELP with NULL DateTime VALUES
    By lfolger in forum Programming
    Replies: 3
    Last Post: 03-28-2008, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums