As DateTime = DateTime.Now....

Hello:

I have a process that runs and would like to preserve the computer time inside of the variable when the process finishes. Using this method
Dim dtDateTimeVar As DateTime = DateTime.Now
the information inside the variable does not stay static and keeps changing with the time... what can I do to work around this?
Need ASP.NET web hosting? Private Message me for a free quote.
0
webd
10/8/2004 8:32:17 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

11 Replies
1123 Views

Similar Articles

[PageSpeed] 43

I have even tried something like this...

Dim dtDateTimeVar as DateTime = DateTime.Now
Dim varOldTime as String
varoldtime = dtDateTimeVar
It still gets the current time instead of the old time..........
Need ASP.NET web hosting? Private Message me for a free quote.
0
webd
10/8/2004 10:08:33 PM
If this variable is in page level, everytime the page load (or reload), it will assigned to current time. You may put it in a session variable.
This posting is provided "AS IS" with no warranties, and confers no rights.
0
jimmym
10/8/2004 10:36:53 PM
Ok I tried using a session variable and it still did not do the trick... maybe my approach is incorrect... I tried:

Dim dtNow As DateTime = DateTime.Now
Session("svarPastTime") = dtNow
then when I output the result of dtNow and svarPastTime variables, they are the same... so it does not work or I am using an incorrect approach.

--------
What I am really trying to do with this code is to select a row from a table in a database using the time that the row was inserted from a a key called 'date'... So this causes the database code to fail because the date it looks for and the date inserted are not the same...
Need ASP.NET web hosting? Private Message me for a free quote.
0
webd
10/9/2004 12:16:46 AM
You may need put more code to show how do you get the session for saved time.
This posting is provided "AS IS" with no warranties, and confers no rights.
0
jimmym
10/9/2004 3:00:54 AM
Note if you have:

Dim dtNow As DateTime = DateTime.Now
Session("svarPastTime") = dtNow
inside your Page_Load event, it will fire each time and therefore the old time will be replaced by the new time. Can you provide more details of what and how you want to achieve what you are doing?
Stanley Tan

theSpoke Blog
0
Stanley
10/9/2004 5:03:55 AM
Here is what I want to achieve:  I want to fire a database action and save the time that the database action was completed to a variable, local or session, whichever works...  The problem I am having is using the code I had showed earlier keeps getting the current time instead...  Below is more code so you can better understand the obstacle that I am facing:

Sub btncontinue_click(ByVal sender As Object, ByVal e As EventArgs)

Dim dtNow As DateTime = DateTime.Now
Session("svarPastTime") = dtNow
'###Database transaction occurs here where a new row
is inserted into the DB with the current time.
'###Then the second database transaction occurs here where I
try to to select the row just inserted based on the time of insertion...
which fails because the session variable always displays the current time
rather than the time the database transaction first took place...
End Sub

My SQL code for selecting goes something like this... "Select * From TB_DATA1 Where [insert date]='" & Session("svarpasttime") & "'"
However the SQL code does not return any results... When I view the contents of the session variable, it shows the current time rather than the past time............ I have also tried placing If Page.ispostback = false around the Session variable, which still does not work...
Need ASP.NET web hosting? Private Message me for a free quote.
0
webd
10/9/2004 8:55:33 AM
After posting the details and searching... I still have not found the right method to overcome this.   Any suggestions at all is appreciated...
Need ASP.NET web hosting? Private Message me for a free quote.
0
webd
10/11/2004 7:46:42 AM
I always just use (vb.net)



dim timestamp = now()

which works just fine for me
hth
Mikieman
0
mikieman
10/11/2004 8:33:40 AM
That still gets the current time everytime rather than saving the current time in a variable then accessing that variable later which should not be the current time anymore...

This really is not working...
What I am doing is creating a record in the DB that contains a field which is a NTEXT variable in SQL... when I try to access that record using inquiry=txtinquiry.text... it does not work because you can not get a record based on ntext... I tried doing it with the time... that does not work either since the time is not preserved... any ideas?
Need ASP.NET web hosting? Private Message me for a free quote.
0
webd
10/11/2004 8:14:44 PM
May be you need give each record a unique ID.
This posting is provided "AS IS" with no warranties, and confers no rights.
0
jimmym
10/11/2004 8:22:00 PM
Ok I went ahead and did that via SQL assigned it an auto incrementing number... I went ahead and executed my select statement by getting the inquiry by the users account name and the last message sent based by the current time...  This method returns the tracking number that I am trying to get at but the only thing is that the tracking number returned is always 1 digit off from the tracking number in the database...

If in the DB the inquiry has a tracking number 2, on the select statement it returns 1 instead of two... I went ahead and added one to the returned tracking number... but why would it do this?
Need ASP.NET web hosting? Private Message me for a free quote.
0
webd
10/11/2004 8:32:19 PM
Reply:

Similar Artilces:

datetime.now and server datetime ?
hi how can i get datetime of server without storedprocedure ? my code is below in *.aspx.vb DateTime.Now() ThanksMark as me if my question or my answer can be helpful for you :) oguzkaygun: hi how can i get datetime of server without storedprocedure ? my code is below in *.aspx.vb DateTime.Now() Thanks Dim dt As Date = Date.Now Dim strtime As String = dt.ToShortTimeString()  MAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets  I don't see what's wrong with what you have. The code you posted does exac...

datetime.now() and datetime.now().addmonths()..insert code run before.. but it doesnt run now... i have no done anything.. why dont it run itself ?
hi datetime.now() and datetime.now().addmonths().. it run before.. but it doesnt run now... i have no done anything.. why doesnt it run now ? my datatype is datetime.. what can problem be ? sds.InsertParameters.Add("ilanbaslangictarihi", DateTime.Now()) hello friends when i change 14.06.2008 to 10.06.2008 from my computer, inserting run for datetime.now() but when i change 10.06.2008 to 14.06.2008 from my computer.. inserting doesnt run for datetime.now() Also when i enter {0:dd/MM/YYYY hh:mm:ss} to formatstring of edit column of gridview, gridview display 33.06.2008 1...

Issue when converting XML dateTime to .NET DateTime
Hi, I am experiencing an issue when deserializing XML dateTime nodes in ASP.NET in some timezones. The construct 0001-01-01T00:00:00.0000000+ZZ:ZZ where ZZ:ZZ is the timezone offset for the timezone on the current system should produce a DateTime value equalling the constant DateTime.MinValue when converted. This works some of the time, such as for the Paris time offset of +1: (CDate("0001-01-01T00:00:00.0000000+01:00") = DateTime.MinValue) = True But does not work for Sydney time offset of +10: (CDate("0001-01-01T00:00:00.0000000+10:00") = DateTime....

.NET DateTime and SQL Server DateTime problem
.NET DateTime and SQL Server DateTime problem  I have the following if statement in an SQL stored procedure: IF (@Image = 1 AND @DateTimeUploaded = (SELECT ImageMainDateTime FROM Images WHERE UserID = @UserID))   The value of the @DateTimeUpdated variable was taken from the ImageMainDateTime field when the data was requested by a ASP.NET webpage and is passed back here when that page is submitted so I can compare what the DateTime was when the data was requested with what it is now, in other words I’m doing a concurrency check (I can’t use TimeStamp for many reasons, ...

Get date portion from DateTime (with DateTime property)
    private string _Date;    public string Date    {        get { return _Date; }        set { _Date = value; }    } objDados.Date = Convert.ToDateTime(drResult["APP_DATE"]).Date.ToString("dd/MM/yyyy"); If I replace _Date from string to DateTime, how can I get only date portion from DateTime? ThanksBest regards,Ivan Andrade Hi  you could always copy it. But I'd put the Date property to be of DateTime type. Something like:  &...

Convert .NET DateTime format to SQL DateTime format
Hi!!I'd like to know if there is a function to convert the DateTime format used in C# (VS2005) : dd/mm/yyyy HH:mm:ss to the format used in SQL Databases: yyyymmdd HH:mm:ssThanks folks!...

Datetime to xsd:datetime
Dear all, i need to create a datetime variable with this format: "2003-02-04T13:58:59.9999999+03:00"? i need the variable in Datetime format not string format.. Thanks. Cisatlantic: Dear all, i need to create a datetime variable with this format: "2003-02-04T13:58:59.9999999+03:00"? i need the variable in Datetime format not string format.. Thanks. So what's the problem?  If you declare a variable as a datetime it will serialize in the above format automatically, and the calling objects will treat it as a date when it receives it. no problems, it worked, thanks...

get DateTime.Now.Date in sql
 Hi, Im making an c# asp.net website. I use an dataset and an gridview.  I will fill an gridview with users with the follow sql query:SELECT     UserIdFROM         StatsWHERE     LunchDate =  DateTime.Now.Date()How can I get all the users with the date of today?I have try the follow solution but it doesnt work:SELECT     UserId FROM         Stats WHERE     LunchDate =  @LunchDateIn the objectDataSource I hav...

convert an sql datetime column to .net datetime data type in front end...?
I have a field (ldate) in a table that typically displays data in the following format:2007-11-12 20:30:47.000In the front end I want the time and the date separately. But as I try to cast it to a datetime object it is giving me a System.NullReferenceException. What I tried to do was just this: Protected Sub gvTopics_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvTopics.RowDataBound Dim img As Image = gvTopics.FindControl("imgIcon") Dim lbDate, lbTime As Label lbDate = gvTopics.FindControl(...

HTLM encodeformatstring of selected field of edit field of gridview ? datetime ? datetime.now () and insert code lines
hi friends i changed HTLM encodeformatstring of selected field of edit field of gridview as false.. i also changed HTLM encode as false..i entered dataformatstring as {0:DD/MM/YYYY} then i tried below code line for inserting record.. datatype of table1 is datatime.. thic code lines run good before i changed HTLM encodeformatstring and HTLM encode and dataformatstring.. but this code lines doesnt run now. inserting of my backup web sites doesnt work.. i think that datetimeformat of my computer changed.. How can i fix it ? What can problem be ? Cheers sds.ConnectionString = C...

getting error : : The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value
update tblPact_2008_0307 set student_dob = '30/01/1996' where student_rcnumber = 1830when entering update date in format such as ddmmyyyyi know the sql query date format entered should be in mmddyyyy formatis there any way to change the date format entered to ddmmyyyy in sql query? Before the update execute: SET DATEFORMAT dmyPlease remember to mark the replies as answers if they help and unmark them if they provide no help. everytime i do a query on date format ddmmyyyy, i need to do a set dateformat dmy?is there anyway to configure the sql server to set the dateformat in dmy as...

From DateTime to xs:dateTime (and back)
This is the kind of thing my XML field is expecting:    2005-11-21T20:31:43.000-00:00How do i get a DateTime variable to that so i can put it into my XML file?!?Thank you! - Callam Can anyone answer this?!...

DateTime.Now () ?
I am using a gridview that is connected to a table adpater. On Insert of a new row I would like for a specific date column to be updated with the system date or the DateTime.Now. I have attempted to set the default value to DateTime.Now() and that did not work for me. Does anyone have a solution for this? Thanks!Jeff  You can use trigger in this case.ThanksPankaj GohelPlease Mark as Answer if you find the post useful. convert that field to template field first, then set the default value to dateTime.now. in dataset, for insert, use the default value in your query.  if you use...

DateTime Now
Hi there,I'm from Argentina. I have two questions for the following code:  CPublicacion pub = new CPublicacion(long.Parse(SecureQueryString["id"]), true);            if (pub.creacion > DateTime.Now)                lblPubModif.Text = "Su venta ha sido publicada con éxito.";              else              &...

Web resources about - As DateTime = DateTime.Now.... - asp.net.getting-started

Is there a JQuery plugin to convert UTC datetimes to local user timezone?
If I have a tag: <span class="utctime">2010-01-01 11:30 PM</span> I would like a jquery script or plug in to convert every utctime ...


Targetprocess 3.7.3: Epic unit for Bug/Story cards, new DateTime functions in Webhook plugin
Webhook plugin supports new DateTime functions AddDays(DateTime date, int days) – Returns a new date with the number of days added. The number ...

Common Pitfalls when working with DateTime’s
In .NET, the DateTime structure provides us wonderful functionality, but this seemingly simple structure can cause a lot of headaches if you ...

Parsing Twitter Date format to .Net DateTime
Recently when I needed to parse the twitter datetime format into a .Net DateTime I found this post on the web showing how to do it. However, ...

C Sharp (programming language) - Wikipedia, the free encyclopedia
(pronounced see sharp ) is a multi-paradigm programming language encompassing strong typing , imperative , declarative , functional , generic ...

1753 - Wikipedia, the free encyclopedia
Language: English Afrikaans አማርኛ العربية Aragonés Asturianu Aymar aru Azərbaycanca বাংলা Bân-lâm-gú Basa Banyumasan Беларуская ‪Беларуская (тарашкевіца)‬ ...

Coded Smorgasbord: Schizophrenic Haiku Comments and More
... writes Malcom StandardResponse UnSubscribeNewsletterUserAccount( string opTinGUID,string email, string sellingRegion, string source, DateTime ...

Limburg.be - Welkom op de site van de provincie Limburg - Welkom_op_de_site_van_de_provincie_Limburg
visit wonen werken leven ontspannen infopunt home op trefwoord contactpersonen wegwijs sitemap print deze pagina Je bent hier: limburg.be Contact ...

Simples Ideias. Por Nando Vieira.
Simples Ideias Siga-me no Twitter Junho/2012 Usando o Vagrant como ambiente de desenvolvimento no Windows http://simplesideias.com.br/usando ...

Resources last updated: 12/7/2015 5:46:59 AM