Results 1 to 7 of 7
  1. #1
    harvella is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    4

    Break apart a date in Access. Example 7/1/2015

    Hi,



    I'm trying to figure out how to take apart a date when I can only pull a full date.

    Example is that my data can only give me 7/1/2015 but I need it to have specific columns for "7", "1", and "2015". I have searched everywhere I can but I'm not sure if I am searching with the correct keywords.

    Thanks for the help.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Here is some more info and an example.
    https://msdn.microsoft.com/EN-US/lib.../gg251733.aspx

    Code:
    Dim intMonth As Integer
    Dim dtMyDate As Date
    dtMyDate = "01/01/2010"
    intMonth = DatePart("m", dtMyDate)
    MsgBox intMonth

  4. #4
    harvella is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    4
    I did find this site but I am fairly new to access and I'm not understanding the way the expression is written. I get that I need to use a datepart expression but I'm not sure if I put the expression category in first or second.

    This is how I am writing based on what I understand but I know its in the wrong order. but I can't figure out exactly how to write it.

    datepart( [Date (Calendar)], "D")



    Quote Originally Posted by orange View Post
    You should try using Google

    MSAccess date functions

    See http://www.techonthenet.com/access/functions/

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What date part are you trying to extract? The example at bottom of link referenced by ItsMe explicitly shows correct syntax.

    Date is a function that has no argument - it simply returns the current system date.

    Is Calendar a field in table?

    DatePart("d", [Calendar])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Did you see and try the examples
    Example

    Let's look at how to use the DatePart function in MS Access:
    DatePart ("yyyy", #15/10/1998#)
    Result: 1998

    DatePart ("m", #15/10/2003#)
    Result: 10

    DatePart ("d", #15/10/2003#)
    Result: 15 Example in VBA Code

    The DatePart function can be used in VBA code in Microsoft Access.
    For example:
    Dim LValue As Integer

    LValue = DatePart ("d", #15/10/2003#) In this example, the variable called LValue would now contain the value of 15.

  7. #7
    IrogSinta is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    103
    While you're learning the very DatePart useful function, might as well learn some other useful Date Functions:
    Month(#7/1/2015#) 'this returns 1
    Day(#7/1/2015#) 'this returns 7
    Year(#7/1/2015#) 'this returns 2015
    Ron

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

Similar Threads

  1. Replies: 1
    Last Post: 06-25-2015, 05:24 AM
  2. Replies: 1
    Last Post: 01-05-2015, 07:05 AM
  3. Replies: 9
    Last Post: 05-07-2013, 08:37 PM
  4. Why break tables up?
    By Canadiangal in forum Database Design
    Replies: 7
    Last Post: 01-11-2013, 01:56 PM
  5. Page break
    By remigio in forum Forms
    Replies: 2
    Last Post: 08-23-2012, 07:59 AM

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