Solved

Create a fixed current timestamp

Posted on 2014-12-29
7
77 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 47

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 47

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

Suggested Solutions

Title # Comments Views Activity
ModalPopup  question 22 56
VB script help 23 50
Web page design problem 3 41
Select coumns form Data table? 3 26
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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