Results 1 to 7 of 7
  1. #1
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55

    Set Date Format in 'Replace' Formula

    Hello and thank you in advance for any attention this post may recieve.

    I am using MS Access 2010 on a Windows XP platform.

    So I have a report containing a text box with the Control Source as a formula to display 'Date' field and 'Title' field as a title (Date : Title). My formula is returning the information I have asked for, but the date is not the format I want.

    My formula is =Replace(Replace("|1 : |2 ","|1",Nz([ProblemDate],"")),"|2",Nz([Title],"(Untitled)"))

    It is returning the date in a 'General Date' format (DD/MM/YY hh:mm:ss PM) where I want it to display as 'Medium Date' (dd-mmm-yy)format.

    I do not know how to write the format into my formula.

    Nadine

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Date field is a date/time type?

    Format([Date], "dd-mmm-yy") & ":" & Nz([Title], "(Untitled)")

    Date is a reserved word. Should avoid reserved words as names.
    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.

  3. #3
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    Hello June

    The field is 'ProblemDate', not 'Date'. Hmmmmm I am unsure if 'ProblemDate' will conflict with reserved word Date.

    I have used your suggestion and now my formula is =Replace(Replace("|1 : |2 ","|1",Format([ProblemDate],"dd-mmm-yy")),"|2",Nz([Title],"(Untitled)")) and it the date (ProblemDate) is exactly as I want it to display (15-Jul-15 : This is my Title).

    Thank you June for once again solving my issue.

    Nadine

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    Also be aware that all dates are actually numbers - what you see as 06/01/2015 or Jan 6th 2015 is just the way it is formatted - so replace won't work unless you use the format function first which turns it into a string

    dates are a decimal number, the value to the left of the decimal point is the number of days from way back when and to the right of the decimal point represents the time expressed as the current time in seconds as a percentage of 24hr x 60min x 60 secs

    so today is 24th July 2015 and the time is 1:24am

    this is stored as 42209.058587963

    Same with currency - the $/£ etc symbol is not stored

  5. #5
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    Oh thank you for that June. I understand how dates are stored more clearly.

    The date was displaying as dd/mm/yy hh:mm:ss before I inserted 'Format' in my formula. Now that 'format' is in there it is displaying how I want/told it to.

    Champion!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Did not notice actual field name was ProblemDate after reading the statement before the expression.

    I did some testing and was surprised that Replace() did work on a date/time value. Examples:

    Replace(Date(), "/", "-")

    returns 7-22-2015

    Replace(Date(), "/", ":")

    returns 7:23:2015

    Weird, I did not expect that.

    Really don't need both Replace and Format. Why not simply:

    Format([ProblemDate], "dd-mmm-yy") & " : " & Nz([Title], "(Untitled)")
    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.

  7. #7
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    Hey there June

    Oh ok I will do that. no need to add more clutter is it makes no difference hey.

    I hope you have a great day!

    Nadine

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

Similar Threads

  1. Converting Excel Formula to Access Query Format
    By Guy Winfield in forum Queries
    Replies: 2
    Last Post: 05-11-2015, 06:21 AM
  2. Format Formula - Text as Number
    By Madmartigan in forum Queries
    Replies: 8
    Last Post: 03-04-2014, 03:23 PM
  3. Replies: 11
    Last Post: 10-18-2013, 01:56 PM
  4. Replies: 4
    Last Post: 03-12-2013, 06:49 PM
  5. Replies: 5
    Last Post: 04-18-2012, 10:54 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