Solved

Create a fixed current timestamp

Posted on 2014-12-29
7
82 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 48

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
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

 
LVL 48

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

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!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

696 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