none
make the day starts 02:00 AM instead of 12:00 AM RRS feed

  • Question

  • hello guys.

    is there any idea to make the starts of day be on 02:00AM hour instead of 12:00AM?

    actually, i have developed a software in vb.net that print a bills of a restaurant.

    this app prints a serial number for customer queue, and this queue number must be reset to 1 every new day.

    my problem is: the day in restaurant  ends on 2:00AM not 12:00AM and the number reset to 1 on 12:00AM not 2:00AM.

    i used this code:

        Private Sub getlastsnum()
            Dim sqlstr As String = "Select max(snum) From tblbill where idate >  '" & Today.Date.ToString("yyyy/MM/dd") & "' "
            Dim anyDataTable As DataTable = clsDBase.GetDataTable(sqlstr)
            If anyDataTable.Rows.Count >= 1 Then
                TextBox6.Text = If(IsDBNull(anyDataTable.Rows(0).Item(0)), 1, anyDataTable.Rows(0).Item(0) + 1)
            End If
        End Sub

    any idea please!

    thanks in advance.


    • Edited by eng.bassel Thursday, November 30, 2017 10:04 AM add code
    Thursday, November 30, 2017 9:25 AM

All replies

  • Whereever you have the implementation to reset the queue number (i am not sure what this even means) to 1, just add an implementation that would check the time as well and not just the day.

    Please be so kind to close your Threads when you found an answer, these Threads should help everyone with similar issues.
    You can close a Thread via the"Mark as Answer" link below posts. You can mark your own posts as answers if you were not helped out but found a solution, in such a case, please provide the answer.
    Happy coding
    PS: I assure everyone that I did not ever had the desire to offend anyone.

    Thursday, November 30, 2017 9:39 AM
  • There are probably  1000 solutions, however as you don't show any code which it affects there are as well 10000000000 possibilities. 

    Therefore show your code where you reset that queue


    Success
    Cor

    Thursday, November 30, 2017 9:42 AM
  • If you want to simulate the time for a unit test then something like this would do while if the requirement was say crossing time zones NodaTime library would be better which has more to it.

    These would go into one or more class files.

    Public Interface IClock
        ReadOnly Property Now() As Date
    End Interface
    Public Class SystemClock
        Implements IClock
    
        Public Overridable ReadOnly Property Now() As Date Implements IClock.Now
            Get
                Return Date.Now
            End Get
        End Property
    End Class
    Public Class FakeClock
        Implements IClock
    
        Private _fakeDateTime As Date
        Public Sub New(ByVal pFakeDateTime As Date)
            _fakeDateTime = pFakeDateTime
        End Sub
        Public Overridable ReadOnly Property Now() As Date Implements IClock.Now
            Get
                Return _fakeDateTime
            End Get
        End Property
    End Class
    

    In a unit test we create the FakeClock

    Dim fakeTime As Date = Date.Parse("11/29/2017 2:00 PM")
    Dim fakeClock = New FakeClock(fakeTime)

    Then pass fakeClock to a method in a unit test method to the class method that you want to test. On the cheap you could simply pass the following to the class method to test yet that is not the preferred way to go, it's unclear while FakeClock is not and can be all done in one place along with the ability to create other clocks via implementing IClock.

    Date.Parse("11/29/2017 2:00 PM")


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 30, 2017 10:40 AM
    Moderator
  •         Dim sqlstr As String = "Select max(snum) From tblbill where idate > @1"
            clsbase.SelectCommand.Parameters.Clear()
            clsbase.SelectCommand.Parameters.AddWithValue("@1,", Now.Date.AddHours(2))
            Dim anyDataTable As DataTable = clsDBase.GetDataTable(sqlstr)
            If anyDataTable.Rows.Count >= 1 Then
                TextBox6.Text = If(IsDBNull(anyDataTable.Rows(0).Item(0)), 1, anyDataTable.Rows(0).Item(0) + 1)
            End If
     


    Success
    Cor

    • Proposed as answer by MDeero Thursday, November 30, 2017 11:27 AM
    Thursday, November 30, 2017 11:23 AM
  • hello guys.

    is there any idea to make the starts of day be on 02:00AM hour instead of 12:00AM?

    actually, i have developed a software in vb.net that print a bills of a restaurant.

    this app prints a serial number for customer queue, and this queue number must be reset to 1 every new day.

    my problem is: the day in restaurant  ends on 2:00AM not 12:00AM and the number reset to 1 on 12:00AM not 2:00AM.


    Hi eng.bassel,

    You said that you want a new day starting at 2:00 AM instead of 12:00 AM, you just need to add two hours for date now.

     Dim datevalue As Date = DateTime.Now.AddHours(2)
            MessageBox.Show(datevalue)

    If you want to reset the number to 1 at 12:AM, you just check the datetime.now using Timer.

      Dim i As Integer
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim timer As New Timer
            timer.Interval = 1000
            timer.Start()
            AddHandler timer.Tick, AddressOf timer_Tick
        End Sub
        Private Sub timer_Tick(sender As Object, e As EventArgs)
            Dim time As String = "12:00 AM"
            Dim datevalue As String = DateTime.Now.ToString("hh:mm tt")
            Dim date1 As Date = Convert.ToDateTime(time).AddDays(1)
            Dim date2 As Date = Convert.ToDateTime(datevalue)
            Dim result As Integer = DateTime.Compare(date1, date2)
            If result > 0 Then
    
            Else
                i = 1
            End If
    
    
        End Sub

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 1, 2017 6:21 AM
    Moderator