• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1602
  • Last Modified:

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

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
vico1
Asked:
vico1
3 Solutions
 
Den_HBRCommented:
MsgBox(Format(DateAdd(DateInterval.Hour, -1, Now), "yyyy-MM-dd HH:mm:ss.fff"))
0
 
JonMnyCommented:


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
 
danaseamanCommented:
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
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.

 
Den_HBRCommented:
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
 
vico1CIOAuthor Commented:
Different versions,
Den's will work best for me.
Thank you all for the quick response.

Vico1
0
 
vico1CIOAuthor Commented:
Thank you Den HBR!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now