Solved

Create a fixed current timestamp

Posted on 2014-12-29
7
68 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
  • 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 46

Accepted Solution

by:
Martin Liss earned 500 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 46

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 33

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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now