Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help comparing dates  VB.NET

Posted on 2012-08-14
2
Medium Priority
?
591 Views
Last Modified: 2012-08-14
Given variables ReceivedDate  and  ProcessDate

I want to run this date through a function and return the result of "ON TIME" or "LATE" and the number of days it is late.

My criteria:
If ReceivedDate is after 12noon on a Friday, then ProcessDate must be by 5pm on Monday, else it is late.
If ReceivedDate is after 12noon on Monday-Thursday then ProcessDate must be by 5pm the next day or else it is late
If ReceivedDate is before 12noon on any weekday, then ProcessDate must be by 5pm that day or it is late.


The function should return "ON TIME" or "Late by X Days" where X = the count of days after required time has past.

Example
ReceivedDate was Tuesday at 9:00am
ProcessDate was Wednesday at 6:00pm
This is 1 day late

ReceivedDate was Tuesday at 7:00PM
ProcessDate was Wednesday at 3:00pm
This is on time

 ReceivedDate was Friday at 7:00am
ProcessDate was Tuesday at 3:00pm
This is 4 days late or 2 days late, im fine either way if weekends are counted or not for computing days late- (It was due Friday by 5pm)

Please help me with VB code, I can't read C
0
Comment
Question by:arthurh88
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 38294141
Following is what I came up with but you may have to fine tune it

    Public Function ProcessDates(sDate As DateTime, eDate As DateTime) As String
        Dim res As String = ""
        If sDate.DayOfWeek <> DayOfWeek.Friday Then
            If sDate.TimeOfDay.Hours < 12 Then
                If eDate.Date = sDate.Date Then
                    If eDate.TimeOfDay.Hours < 17 Then
                        res = "On Time"
                    Else
                        res = "Late By 1 Day"
                    End If
                Else
                    Dim days As Integer = (eDate.Date - sDate.Date).Days
                    If days < 1 Then
                        days = 1
                    End If
                    res = "Late By " & days & " Day(s)"
                End If
            End If
        Else
            If sDate.TimeOfDay.Hours < 12 Then
                If eDate.Date = sDate.Date Then
                    If eDate.TimeOfDay.Hours < 17 Then
                        res = "On Time"
                    Else
                        res = "Late By 1 Day"
                    End If
                Else
                    res = "Late By " & (eDate - sDate).Days - 2 & " Day(s)"
                End If
            End If
        End If
        Return res
    End Function

Open in new window

0
 

Author Closing Comment

by:arthurh88
ID: 38294303
thank you!  with some tweaking, i got it to work perfectly.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question