hi,

How do i check for time difference for eg: i have code like this

If GetServerDateTime() < Format(Now, "MM/dd/yyyy hh:mm:ss tt") Then
msgbox ("Invalid datetime")
endif

i want to make it like if the time difference is within 2 min from the current time.... the application still can allowed to next form. Is there a specific code to do this....just to check the minute difference

Edited 5 Years Ago by swathys: n/a

See if this helps.

MsgBox(Format(Now.AddMinutes(5), "MM/dd/yyyy hh:mm:ss tt"))
        MsgBox(Format(Now.AddMinutes(-5), "MM/dd/yyyy hh:mm:ss tt"))

hi codeorder,

i have code something like this but not get the aactual understanding of it. please help me to solve this....can you modify in my code itself..thank you

If GetServerDateTime() > Format(Now, "MM/dd/yyyy hh:mm:ss tt") Then

                Dim tm1 As String = Format(Now, "MM/dd/yyyy hh:mm:ss tt")
                Dim tm2 As String = (Format(Now.AddMinutes(-2), "MM/dd/yyyy hh:mm:ss tt"))
                Dim tm3 As String = tm2 - tm1
                If tm2 < GetServerDateTime() Then

                    Debug.Print("GetServerDateTime()= " & GetServerDateTime())
                    Debug.Print("Now= " & Now)
                    MsgBox("ddd")

                    'frmPopup1.lblErrMsg.Text = GetButtonText("InvalidDateTime")
                    'frmPopup1.YesNo = False
                    'frmPopup1.QorEx = False
                    'frmPopup1.ShowDialog()
                    'Application.Exit()
   
                    End
                End If
            End If

try this .

If GetServerDateTime() < (Format(Now.AddMinutes(-2), "MM/dd/yyyy hh:mm:ss tt")) Then
msgbox ("Invalid datetime")
end if

You may need to format it a bit.

Comments
don't post if you can't give proper solution

i need to code for this but but i still don't get the clear picture on how to do it....please guide


if my server datetime = 03/29/2011 03:12:36 and pc datetime = 03/29/2011 03:12:36 then i allow the application to proceed
if
if my server datetime = 03/29/2011 03:12:36 and pc datetime = 03/29/2011 03:14:36 then i allow the application to proceed
if
server datetime = 03/29/2011 03:12:36 and pc datetime = 03/29/2011 03:20:36 then i exit application
if
server datetime = 03/29/2011 03:12:36 and pc datetime = 03/20/2011 03:20:36 then i exit application
if
server datetime = 03/29/2011 03:12:36 and pc datetime = 03/28/2011 02:20:36 then i exit application

Comments
don't post garbage here.

You have been supplied with enough logic by way of sample code.

Now its time for you to show effort.

Try to code the logic that you want to implement and post the code here.

hi debasisdas,

if you can't come out with the proper solution then please don't reply on my question...i send a question to get a solution which i don't understand to solve it....

Comments
don't show attitude here.
We don't GIVE proper solution. We give help so YOU get the proper solution

ohh.....

if you do not understand the question itself how will you get the solution ?

and you should not try to offend those who try to help you.

Edited 5 Years Ago by debasisdas: typo

its not THOSE its YOU !!! did i mention i did not understand the question. please read the the English statement correctly...

Comments
stop misbehaving.

The only thing I did not see in this thread is:
Use the difftime() function check the time difference.


But what I do see is a lot of help given and no attempt, only attitude, from the person asking for help. Please reread this thread and try using the help given.

EXCUSE ME !!
what do u mean by this ..only attitude, from the person asking for help
i don't think so i need an advice or some other unrelated things to be posted other than a answer for my question....as this is the public forum that i can send a question's as i wish...STOP from post a nonsense thing other than a answer for my question.

Comments
bad, bad ,bad attitude.

Some people post here looking for help. Others post to have their problems done for them.

We've given you help. 4 different suggestions and code.
You complained. You want us to write the code for you. Sorry. That's not how this public forum works.

If you want to post more information to help us understand what you don't understand, please do. But right now, I guess we don't really know what you need.

If GetServerDateTime.ToString("MM/dd/yyyy hh:mm:ss tt") < Format(Now, "MM/dd/yyyy hh:mm:ss tt") Then
msgbox ("Invalid datetime")
endif

Use like this..........
Hope it will helps u.

I am personally not clear of what GetServerDateTime returns/is/or does, but see if this helps.

Dim dtServer As DateTime = CDate(Format(GetServerDateTime, "MM/dd/yyyy hh:mm:ss tt")).AddMinutes(+2) '// server date/time.
        Dim dtUser As DateTime = CDate(Format(Now, "MM/dd/yyyy hh:mm:ss tt")) '// date/time on user p.c..
        If dtServer >= dtUser Then '// check if the server date/time +2 minutes, equals or is greater than the users p.c. time.
            MsgBox("allow")
        Else
            MsgBox("cancel")
        End If
Comments
thank you so much your reply solve my problem !
' set the previous date/time here
        Dim theTime As Date = New Date(2011, 3, 29, 10, 38, 4, 0)

        ' check it
        If DateDiff(DateInterval.Minute, theTime, Now) < 2 Then
            MsgBox("less than 2 minutes")
        Else
            MsgBox("whatever")
        End If

I will not post an answer for this one, because I saw enough code. What is missing here is just "a nonsense thing other than a answer".

You come to here for an answer, which is good. But the answer is not free. You need to pay with your own effort. That is a common sense, not a "nonsense". Get it?

This one should be solved now.

Comments
thanks for the counter NONSENSE campaign.
i don't prefer a nonsence answer from you too....u got it !!

thank you so much !! i manage to solve from the answer given.... for those who are giving nonsense reply DO STOP it...as this is not your personal web forum....this forum meant to be a public and i can ask question as i wish for.. for those who not able to give a solution then you should not reply a NONSENSE things on my thread....as i waste my bloody time to read these nonsense ....so simple like that...hope you got it!!!

Comments
misbehaving idiot.
This question has already been answered. Start a new discussion instead.