Solved

Date Difference and display format: Format: yyyy-MM-dd HH:mm:SS.xxx

Posted on 2010-11-19
6
1,406 Views
Last Modified: 2012-05-10
I need to Display the Current date and time - (minus)1 hours to the following format: Format: yyyy-MM-dd HH:mm:SS.xxx

can someone help me?

Thank you in advance.
0
Comment
Question by:vico1
6 Comments
 
LVL 8

Expert Comment

by:Den_HBR
ID: 34177098
MsgBox(Format(DateAdd(DateInterval.Hour, -1, Now), "yyyy-MM-dd HH:mm:ss.fff"))
0
 
LVL 9

Assisted Solution

by:JonMny
JonMny earned 50 total points
ID: 34177151


mydate=DateAdd("h",1,Now)
MsgBox DatePart("yyyy",mydate) & "-" & DatePart("m",mydate) & "-" & DatePart("d",mydate) & " " & DatePart("h",mydate) & ":" &  DatePart("n",mydate) & ":" &  DatePart("s",mydate)  

0
 
LVL 22

Assisted Solution

by:danaseaman
danaseaman earned 50 total points
ID: 34178022
For 10ms accuracy you can use Timer.
For  1 ms accuracy you need to use API GetSystemTime.

Sample code for both methods:
Option Explicit



Private Type SYSTEMTIME

        wYear As Integer

        wMonth As Integer

        wDayOfWeek As Integer

        wDay As Integer

        wHour As Integer

        wMinute As Integer

        wSecond As Integer

        wMilliseconds As Integer

End Type



Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)



Private Sub Form_Load()

   Dim typTime As SYSTEMTIME

   

   GetSystemTime typTime

   Debug.Print Format$(DateAdd("h", -1, Now), "yyyy-MM-dd HH:mm:ss.") & Format$(typTime.wMilliseconds, "000"), " 1 Millisecond accuracy"

   Debug.Print Format$(DateAdd("h", -1, Now), "yyyy-MM-dd HH:mm:ss.") & Right$(Format$(Timer, "#0.000"), 3), "10 Millisecond accuracy"

End Sub

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 8

Accepted Solution

by:
Den_HBR earned 400 total points
ID: 34179924
I'm sorry.
Didn't saw it was for asp
<%@ LANGUAGE="VBSCRIPT" %>

<HTML>

<HEAD>

<TITLE>ASP Test Page</TITLE>

<%

Function GetCurrentDateAndTimeMinus1Hour()

	Dim timeStamp

        Dim dateStamp

	timeStamp = Timer

	dateStamp = Now()

	if timeStamp < 3600 then

            dateStamp = DateAdd("h", -1, Now) 'substract a day

	    timeStamp = timeStamp + 86400     'add a day	

	end if

	timeStamp = timeStamp - 3600

	Dim dateAndTime

	'year

	dateAndTime = dateAndTime & DatePart("yyyy",dateStamp)

	dateAndTime = dateAndTime & "-"

	'month

        dateAndTime = dateAndTime & right("0" & DatePart("m",dateStamp),2)

	dateAndTime = dateAndTime & "-"

	'day

        dateAndTime = dateAndTime & right("0" & DatePart("d",dateStamp),2)

	dateAndTime = dateAndTime & " "	

        'hour

        dateAndTime = dateAndTime & right("0" & Fix(timeStamp / 3600),2)

	dateAndTime = dateAndTime & ":"

        'minute

        timeStamp = timeStamp - (Fix(timeStamp / 3600)*3600)

        dateAndTime = dateAndTime & right("0" & Fix(timeStamp / 60),2)

	dateAndTime = dateAndTime & ":"

        'second

        timeStamp = timeStamp - (Fix(timeStamp / 60)*60)

        dateAndTime = dateAndTime & right("0" & Fix(timeStamp),2)

	dateAndTime = dateAndTime & "."

        'millisecond

        timeStamp = Fix((timeStamp - Fix(timeStamp))*1000)

        dateAndTime = dateAndTime  & right("00" & timeStamp ,3)

	

	GetCurrentDateAndTimeMinus1Hour = dateAndTime

End Function

%> 



</HEAD>



<BODY>

<%=GetCurrentDateAndTimeMinus1Hour %>

</BODY>

</HTML>

Open in new window

0
 
LVL 15

Author Comment

by:vico1
ID: 34180110
Different versions,
Den's will work best for me.
Thank you all for the quick response.

Vico1
0
 
LVL 15

Author Closing Comment

by:vico1
ID: 34180119
Thank you Den HBR!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now