Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> QuerySpec get current date
 

Pages: 1
LLBLGen Pro Runtime Framework
QuerySpec get current date
Page:1/1 

  Print all messages in this thread  
Poster Message
scotru
User



Location:
College Place, WA
Joined on:
16-Feb-2006 01:03:42
Posted:
104 posts
# Posted on: 16-Apr-2018 19:08:38.  
Is there a built in way to map to the database's method for getting the current DATETIME in QuerySpec? For example GETDATE() in SQL Server or NOW() in MySQL?

I'm trying to map the following MySQL SQL fragment to QuerySpec:

IF (DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthday, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthday, '00-%m-%d')) < 18, 1, 0) AS is_underage


  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14585 posts
# Posted on: 16-Apr-2018 20:53:36.  
Though for such functions I'd fall for code side date (i.e. getting the current date at the back end server rather than the DB).

But you can use FunctionMappings for such non built-in functions.


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37870 posts
# Posted on: 17-Apr-2018 11:13:42.  
Dateformat isn't mapped by default for MySQL so indeed you need to add a custom function mapping for that function. If you can't figure it out, just post what you got that doesn't work and we'll help you through it.

DateAdd() is mapped for MySQL as a function. (so in queryspec you can use DateTimeFunctions.AddDays etc.) and the Day/Year/Month etc. properties of DateTime are mapped as well, and which are available as properties on DateTimeFunctions as methods. So e.g.
Code:
myQuery.Select(DateTimeFunctions.Year(YourEntityFields.Birthday).As("BirthdayYear"))


selects the year value of the birthday field from the query in myQuery.

The function to map you're after is likely 'DateDiff' which substracts two dates, so you can do birthday + 18 years (using DateAdd, which is mapped) and then check whether datediff that with NOW() gives a negative or a positive value. (
Code:
DateDiff(now(), DateAdd(birthday, YEAR, 18)) > 0
-> under age )
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.