Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you add the values of a date ? dd , mm ,yyyy together

Status
Not open for further replies.

Panchovia

Programmer
May 6, 2010
48
CW
Hi

I am trying to get a number from a date with the following code with out any succes
Alias_Date number: Val([Alias_date],"dd")+Val([Alias_date],"MM")+Val(Alias_date],"yyyy")
 
It would help if you provided some sample values and desired outputs.
Since today is July 14, 2015 it looks like you want 14 + 7 + 2015 which = 2037 which makes no sense. Do you want a number of 14072015? If so, try

Code:
Val(Format([Alias_date],"ddmmyyyy"))

Duane
Hook'D on Access
MS Access MVP
 
Maybe the OP wants...
Code:
Dim DateString As String
DateString = Format([Alias_date],"ddmmyyyy")
...which is all numeric characters, but is NOT a Date NUMBER
 
Hi Dhookom
That is exactly what I want
14+7+2015 =2037
After that I want to add 2+0+3+7

For you it doesn't make any sense for me it does.

So don't bother what is the code to accomplish this
 
Well what code have you tried?

Where are you stuck?

BTW, what's the business case for this exersize?
 
My bad on the 2037.

I would create a small user-defined function and save it in a module named "modConversions"

Code:
Public Function NumFromDate(datDate As Date) As Long
    Dim intFirst As Integer
    Dim strFirst As String
    Dim intI As Integer
    intFirst = Day(datDate) + Month(datDate) + Year(datDate)
    strFirst = CStr(intFirst)
    For intI = 1 To 4
        NumFromDate = NumFromDate + Val(Mid(strFirst, intI, 1))
    Next
End Function

You can use this function anywhere in Access that you would use any other function.

Duane
Hook'D on Access
MS Access MVP
 
> might be a type of weird checksum calculation that validated some data entry. It's difficult to tell
>So don't bother what is the code

Indeed. And apparently we probably shouldn't worry out pretty little heads about this ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top