DateAdd as a string (1 Viewer)

MattioMatt

Registered User.
Local time
Today, 08:09
Joined
Apr 25, 2017
Messages
99
Hello,

Is it possible to output the results of the DateAdd function as a string in a query?

I'm currently using the DateAdd function to work out a date 6 months (Field Name: DueDate) from a date specified from another field (Field Name: ValidatedDate). I'm then wanting this to output a status that will be for example "Overdue [26/07/2018]". The date part being what the DataAdd result is, I'm hoping that makes sense?

I'm having trouble outputting the result in a string - any help much appreciated.
 

June7

AWF VIP
Local time
Yesterday, 23:09
Joined
Mar 9, 2014
Messages
5,501
Why do this in a query? Why not build a report and expression in textbox can concatenate text with date field.
 

isladogs

MVP / VIP
Local time
Today, 08:09
Joined
Jan 14, 2017
Messages
18,272
If DueDate is always 6 months after ValidatedDate, then the field isn't needed as it can be calculated as required

For your string, you can use:
Code:
"Overdue & [" & DateAdd("m",6,ValidatedDate) & "]"

e.g. "Overdue & [" & DateAdd("m",6,#7/26/2018#) & "]" gives
- Overdue & [01/26/2019] in mm/dd/yyyy format
- Overdue & [26/01/2019] in dd/mm/yyyy format
 

Insane_ai

Not Really an A.I.
Local time
Today, 03:09
Joined
Mar 20, 2009
Messages
264
I think Ridders answer is the better one but this addresses the exact question:



Code:
Private Sub Command0_Click()
Dim datDueDate As Date
Dim datPlusSix As Date
Dim strMessage As String

    datDueDate = #12/5/2018#                    'Use your date field here
    datPlusSix = DateAdd("m", 6, datDueDate)
    strMessage = "Overdue " & Format(datPlusSix, "dd/mm/yyyy")
    
    MsgBox strMessage
End Sub
 

Users who are viewing this thread

Top Bottom