DateTime from SQL Server

Posts   
 
    
coderdude
User
Posts: 10
Joined: 24-Apr-2006
# Posted on: 12-May-2006 21:01:49   

I've search the forums and can't seem to find a definate answer on this...

From my web app, I want to update a field called "DateUpdated" with the current date/time each time I update a row.

The "DateUpdated" column must be a user readable date/time.

I want to use the date/time from the SQL Server (i.e. GETDATE()) not from the web server (i.e. Date.Now)

I want to do so without making an extra call to SQL Server to retrieve the time.

I want to do so without the use of triggers.

Is this possible?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 13-May-2006 02:58:36   

Try setting the default value for the field to GETDATE() in sql server. Then once you save the field it will be refetched with the date.

coderdude
User
Posts: 10
Joined: 24-Apr-2006
# Posted on: 13-May-2006 23:31:41   

I have done this, however, it will only populate the "DateUpdated" field in the table when the row is initially created. I would like the field in the table to be updated to the current date/time each time the row is updated.

Normally I would just add this to my SQL Update statement:

UPDATE Table SET SomeField = @SomeValue, DateUpdated = GETDATE() WHERE xxx

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 15-May-2006 14:58:36   

Implement IExpression.

Please check the following thread for more details: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3829

coderdude
User
Posts: 10
Joined: 24-Apr-2006
# Posted on: 15-May-2006 16:43:10   

Thanks Walaa. This looks like it will do what I was searching for.

lubo278
User
Posts: 32
Joined: 10-Apr-2007
# Posted on: 06-Nov-2009 14:34:59   

Sorry for hijacking thread:

I was just wondering. Is it possible to call this query?

SELECT GetDate()

I can only call

SELECT GetDate() FROM MyTable

but if ths MyTable is empty, it will return empty dataset.

Of course workaround would be stored procedure with only one line of code.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Nov-2009 22:18:51   

lubo278 wrote:

Sorry for hijacking thread:

The next time is better if you open a new thread.

lubo278 wrote:

I was just wondering. Is it possible to call this query?

SELECT GetDate()

I can only call

SELECT GetDate() FROM MyTable

but if ths MyTable is empty, it will return empty dataset.

Of course workaround would be stored procedure with only one line of code.

Indeed the SP is the best way to go. You also could execute raw sql: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=12293

David Elizondo | LLBLGen Support Team