[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-11-19
6
Medium Priority
?
1,546 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 200 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 200 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 1600 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

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!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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