PDA

View Full Version : [SOLVED] Compute Date



RobertBC
03-04-2005, 05:17 AM
:help

Good Day!, i have this scenario...

Column A i have this Date "10/10/2005" as Date Shipped
Column B i have the value "Recieved: 11:30 PM 10/14/2005 Note:NameHere" as Date Recieved

my question is how can i compute or maybe create a macro/procedure in order to get the # of days by subtracting Date Recived and Date Shipped to get the transit days. regardless the no of rows to compute.

tnx :friends:

mjmmendoza
03-04-2005, 05:38 AM
DATEDIF(start_date,end_date,unit)

Start_date is a date that represents the first, or starting, date of the period. Dates may be entered as text strings within quotation marks (for example, "2001/1/30"), as serial numbers (for example, 36921, which represents January 30, 2001, if you're using the 1900 date system), or as the results of other formulas or functions (for example, DATEVALUE("2001/1/30")). For more information about date serial numbers, see NOW (mk:@MSITStore:C:Program%20FilesMicrosoft%20OfficeOffice1033xlmain9.chm::/html/xlfctNOW.htm).

End_date is a date that represents the last, or ending, date of the period.

Unit is the type of information you want returned.

UnitReturns"Y"The number of complete years in the period."M"The number of complete months in the period."D"The number of days in the period."MD"The difference between the days in start_date and end_date. The months and years of the dates are ignored."YM"The difference between the months in start_date and end_date. The days and years of the dates are ignored. "YD"The difference between the days of start_date and end_date. The years of the dates are ignored.

RobertBC
03-04-2005, 07:21 AM
here is my solution with the problem i had post, thanks for the help of my friends.

I just want to share it with you for your reference.

:thumb



Sub DateDifference()
Dim Cellcontent
Dim ReceivedDate As Date
Dim ShippedDate As Date
Dim RowNum As Integer
Dim DaysElapsed As Integer
Dim LastRow
LastRow = Range("A65536").End(xlUp).Row
For RowNum = 2 To LastRow
Cellcontent = Split(Cells(RowNum, "AB"), " ")
If Cellcontent(1) <> "" Then
If IsDate(Cellcontent(1)) Then
ReceivedDate = CDate(Cellcontent(1))
ShippedDate = Cells(RowNum, "B")
DaysElapsed = DateDiff("d", ShippedDate, ReceivedDate)
Cells(RowNum, "BJ") = DaysElapsed - 1
End If
End If
Next
End Sub