Solved

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

Posted on 2010-11-19
6
1,462 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
Industry Leaders: 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

717 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