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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with dates 1

Status
Not open for further replies.
Jul 17, 2003
66
0
0
US
My database stores dates in YYYYMMDD format. I have a form that inputs dates in a date format i.e. 2/6/2006. I am trying to convert this into the YYYYMMDD format to save to the database. So far this is the code I have.

Code:
nYear = DatePart("yyyy", [receiptDate])
    nMonth = DatePart("m", [receiptDate])
    nDay = DatePart("d", [receiptDate])
    cCombinedDate = CStr(nYear) & CStr(nMonth) & CStr(nDay)
    [transfer_dt] = CLng(cCombinedDate)

This sort of works except that when the date entered is 2/9/2006 the transfer_dt is written as 200629 instead of 20060209. How do I get the leading 0 in there for the day and month when appropriate?

Thanks ...
 
nMonth = format(nMonth, "00")

same with day.

Randall Vollen
National City Bank Corp.
 
And the oneliner way:
[transfer_dt] = CLng(Format([receiptDate], "yyyymmdd")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OOps, sorry for the typo:
[transfer_dt] = CLng(Format([receiptDate], "yyyymmdd"))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top