?
Solved

Create a fixed current timestamp

Posted on 2014-12-29
7
Medium Priority
?
86 Views
Last Modified: 2015-01-02
Is it possible to create a fixed timestamp from the now function

At present i am using now and then manipulating the date but the result keeps changing as now keeps changing.

Can i take a snapshot of now that remains fixed?
0
Comment
Question by:SweetingA
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 40522441
You could assign a variable to hold the initial value of Now and then use the variable in place of any other calls to Now.
0
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 40522447
Dim MyDate As Date

MyDate = Now() ' Do you want the date formatted?

blah = MyDate
0
 

Author Comment

by:SweetingA
ID: 40522449
I did that already and the variable keeps changing
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 49

Expert Comment

by:Martin Liss
ID: 40522464
Variables don't change unless you change them somehow like if you run the above code several times.

Please show the code that uses Now().
0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 40522465
Post your code and we can advise.
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40522477
Now() may change, but the value in MyDate *does not* change.  Consider the following:
Module Module1
	Private MyDate As Date

	Sub Main()
		MyDate = Now()
		Console.WriteLine("The date variable is: {1}.{0}While the current system time is: {2}", Environment.NewLine, MyDate.ToString("hh:mm:ss tt"), Now().ToString("hh:mm:ss tt"))
		System.Threading.Thread.Sleep(10000)
		Console.WriteLine()
		Console.WriteLine("After sleeping for 10 seconds...")
		Console.WriteLine("The date variable is: {1}.{0}While the current system time is: {2}", Environment.NewLine, MyDate.ToString("hh:mm:ss tt"), Now().ToString("hh:mm:ss tt"))
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40522508
And, because each operation takes a certain amount of time to process.  Once I set the MyDate value as Now() and then produce an output using a new call to Now().  MyDate and Now() actually are not the same value (they are actually milliseconds apart).  To illustrate:
Module Module1
	Private MyDate As Date

	Sub Main()
		MyDate = Now()
		Console.WriteLine("The date variable is: {1}.{0}While the current system time is: {2}{0}Is MyDate equal to Now()? {3}", Environment.NewLine, MyDate.ToString("hh:mm:ss tt"), Now().ToString("hh:mm:ss tt"), MyDate.Equals(Now()))
		System.Threading.Thread.Sleep(10000)
		Console.WriteLine()
		Console.WriteLine("After sleeping for 10 seconds...")
		Console.WriteLine("The date variable is: {1}.{0}While the current system time is: {2}{0}Is MyDate equal to Now()? {3}", Environment.NewLine, MyDate.ToString("hh:mm:ss tt"), Now().ToString("hh:mm:ss tt"), MyDate.Equals(Now()))
		Console.ReadLine()
	End Sub
End Module

Open in new window

Now produces -Capture.JPG-saige-
0

Featured Post

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.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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