Solved

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

Posted on 2010-11-19
6
1,448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Diminish Pop-up  in 3 seconds 7 77
Html split(text) 2 48
Count text color with conditional formating in Excel 4 67
SQL Server 2012 to SQL Server 2016 24 54
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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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