How to get the database's current date?

Posts   
 
    
cabral avatar
cabral
User
Posts: 16
Joined: 24-Oct-2005
# Posted on: 18-Jan-2006 15:03:46   

Hi

I want to set a field value to the database's current date and time. I don't know if that is possible in all databases, but I know how to do it in the following ones:

SQL Server: "Field = getdate()" Oracle: "Field = sysdate" Interbase: "Field = current_timestamp"

Can I use some kind of expression in the Dynamic Query Engine of LLBLGen Pro?

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jan-2006 15:19:16   

If you want to set the field in an Insert Statement, just let the database default value be getDate() and don't set anything in code.

If this is required in an update, then you may either use a Stored Procedure for the update or a trigger.

cabral avatar
cabral
User
Posts: 16
Joined: 24-Oct-2005
# Posted on: 18-Jan-2006 17:59:49   

Walaa wrote:

If you want to set the field in an Insert Statement, just let the database default value be getDate() and don't set anything in code.

If this is required in an update, then you may either use a Stored Procedure for the update or a trigger.

Hmmm... That will not work. I want something like "getdate() - datefield > 2". Well, in other words, that's not possible with LLBL, right?

Thanks anyway...

Posts: 65
Joined: 07-Dec-2005
# Posted on: 18-Jan-2006 18:48:30   

If the scenario is something like a different date/time between the server and the client, then the following suggestion won't work. Or, if you're a purist (read: hardheaded wink ) like I am and insist on using getdate(), then it won't work either. If neither applies to you, then you could simply construct your predicate in a different way. Rather than the desired output of..

getdate() - dateField > 2, the following does the same thing

dateField < 'current date here' - 2

which can be done like so...

<YourNamespace>.HelperClasses.ThisEntitysFields.DateField < DateTime.Now-new TimeSpan(2,0,0,0)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Jan-2006 06:55:17   

I'm confused whether you want to Set a field with GetDate() or you want to use "getdate() - datefield > 2", possibly in a Where clause ?!!

If the earlier is the case then either to use my earlier suggestions or do it programatically as so: YourEntity.YouDateFiled = DateTime.Now

If the later is the case then please check the following long list of threads: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2744 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3829 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5123 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3222

Good Luck