how to persist a Date in a legacy database format

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

how to persist a Date in a legacy database format

chichibek bros
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks


Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

Octavian Covalschi
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...

On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks



Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

chichibek bros
thanks Octavian Covalschi  but why is the reason for this warning!

2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks




Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

sergiomichels
In the persistence the date will be parsed for the format that MySQL needs. Formatting dates should be responsibility of the presentation.

Also, in beforeUpdate you set the "dateCreated", is this correct or should it be beforeInsert?

If I'm not mistaken, if you define "dateCreated" and / or "lastUpdated" Grails will handle this fields for you.



On Tue, Aug 28, 2012 at 3:09 PM, chichibek bros <[hidden email]> wrote:
thanks Octavian Covalschi  but why is the reason for this warning!


2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks





Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

chichibek bros
the reason to do this is because i need to query the database quering date fields, the fields in the database are in this format 
2012-08-28 13:18:41.816, im using jquery ui datapicker to get the date value but when i try to run the query i get no result, i was thinking the reason is because the format are not the same... that why i want to save date values in this format yyyy-DD-mm... 

any suggestion

thanks again







2012/8/28 Sergio Michels <[hidden email]>
In the persistence the date will be parsed for the format that MySQL needs. Formatting dates should be responsibility of the presentation.

Also, in beforeUpdate you set the "dateCreated", is this correct or should it be beforeInsert?

If I'm not mistaken, if you define "dateCreated" and / or "lastUpdated" Grails will handle this fields for you.



On Tue, Aug 28, 2012 at 3:09 PM, chichibek bros <[hidden email]> wrote:
thanks Octavian Covalschi  but why is the reason for this warning!


2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks






Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

sergiomichels
Can you post your query?


On Tue, Aug 28, 2012 at 4:42 PM, chichibek bros <[hidden email]> wrote:
the reason to do this is because i need to query the database quering date fields, the fields in the database are in this format 
2012-08-28 13:18:41.816, im using jquery ui datapicker to get the date value but when i try to run the query i get no result, i was thinking the reason is because the format are not the same... that why i want to save date values in this format yyyy-DD-mm... 

any suggestion

thanks again







2012/8/28 Sergio Michels <[hidden email]>
In the persistence the date will be parsed for the format that MySQL needs. Formatting dates should be responsibility of the presentation.

Also, in beforeUpdate you set the "dateCreated", is this correct or should it be beforeInsert?

If I'm not mistaken, if you define "dateCreated" and / or "lastUpdated" Grails will handle this fields for you.



On Tue, Aug 28, 2012 at 3:09 PM, chichibek bros <[hidden email]> wrote:
thanks Octavian Covalschi  but why is the reason for this warning!


2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks







Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

chichibek bros
this is the hql
def domainInstanceList = Request.findAll('from Request as r where r.dateAnswer between :d1 and :d2',[d1:params.date1,d2:params.date2])

this way i get this error message 
java.lang.String cannot be cast to java.util.Date

params.date1 and params.date2 are values from a jquery ui datepicker whit this format 

$("#date1").datepicker({dateFormat: 'yy-mm-dd'});
$("#date2").datepicker({dateFormat: 'yy-mm-dd'});

this was my fist problem pass from string to date i found some information to do this using parse method

def date1 = new Date().parse("yyyy-MM-dd", params.date1)
def date2 = new Date().parse("yyyy-MM-dd", params.date2)

its work it convert String to Date but the result of the query is always empty



2012/8/28 Sergio Michels <[hidden email]>
Can you post your query?


On Tue, Aug 28, 2012 at 4:42 PM, chichibek bros <[hidden email]> wrote:
the reason to do this is because i need to query the database quering date fields, the fields in the database are in this format 
2012-08-28 13:18:41.816, im using jquery ui datapicker to get the date value but when i try to run the query i get no result, i was thinking the reason is because the format are not the same... that why i want to save date values in this format yyyy-DD-mm... 

any suggestion

thanks again







2012/8/28 Sergio Michels <[hidden email]>
In the persistence the date will be parsed for the format that MySQL needs. Formatting dates should be responsibility of the presentation.

Also, in beforeUpdate you set the "dateCreated", is this correct or should it be beforeInsert?

If I'm not mistaken, if you define "dateCreated" and / or "lastUpdated" Grails will handle this fields for you.



On Tue, Aug 28, 2012 at 3:09 PM, chichibek bros <[hidden email]> wrote:
thanks Octavian Covalschi  but why is the reason for this warning!


2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks








Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

sergiomichels
In your previous post I can see that you store a date with minutes and seconds. date1 and date2 have different dates?


On Tue, Aug 28, 2012 at 5:14 PM, chichibek bros <[hidden email]> wrote:
this is the hql
def domainInstanceList = Request.findAll('from Request as r where r.dateAnswer between :d1 and :d2',[d1:params.date1,d2:params.date2])

this way i get this error message 
java.lang.String cannot be cast to java.util.Date

params.date1 and params.date2 are values from a jquery ui datepicker whit this format 

$("#date1").datepicker({dateFormat: 'yy-mm-dd'});
$("#date2").datepicker({dateFormat: 'yy-mm-dd'});

this was my fist problem pass from string to date i found some information to do this using parse method

def date1 = new Date().parse("yyyy-MM-dd", params.date1)
def date2 = new Date().parse("yyyy-MM-dd", params.date2)

its work it convert String to Date but the result of the query is always empty



2012/8/28 Sergio Michels <[hidden email]>
Can you post your query?


On Tue, Aug 28, 2012 at 4:42 PM, chichibek bros <[hidden email]> wrote:
the reason to do this is because i need to query the database quering date fields, the fields in the database are in this format 
2012-08-28 13:18:41.816, im using jquery ui datapicker to get the date value but when i try to run the query i get no result, i was thinking the reason is because the format are not the same... that why i want to save date values in this format yyyy-DD-mm... 

any suggestion

thanks again







2012/8/28 Sergio Michels <[hidden email]>
In the persistence the date will be parsed for the format that MySQL needs. Formatting dates should be responsibility of the presentation.

Also, in beforeUpdate you set the "dateCreated", is this correct or should it be beforeInsert?

If I'm not mistaken, if you define "dateCreated" and / or "lastUpdated" Grails will handle this fields for you.



On Tue, Aug 28, 2012 at 3:09 PM, chichibek bros <[hidden email]> wrote:
thanks Octavian Covalschi  but why is the reason for this warning!


2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks









Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

chichibek bros
yes it can be differents dates

2012/8/28 Sergio Michels <[hidden email]>
In your previous post I can see that you store a date with minutes and seconds. date1 and date2 have different dates?


On Tue, Aug 28, 2012 at 5:14 PM, chichibek bros <[hidden email]> wrote:
this is the hql
def domainInstanceList = Request.findAll('from Request as r where r.dateAnswer between :d1 and :d2',[d1:params.date1,d2:params.date2])

this way i get this error message 
java.lang.String cannot be cast to java.util.Date

params.date1 and params.date2 are values from a jquery ui datepicker whit this format 

$("#date1").datepicker({dateFormat: 'yy-mm-dd'});
$("#date2").datepicker({dateFormat: 'yy-mm-dd'});

this was my fist problem pass from string to date i found some information to do this using parse method

def date1 = new Date().parse("yyyy-MM-dd", params.date1)
def date2 = new Date().parse("yyyy-MM-dd", params.date2)

its work it convert String to Date but the result of the query is always empty



2012/8/28 Sergio Michels <[hidden email]>
Can you post your query?


On Tue, Aug 28, 2012 at 4:42 PM, chichibek bros <[hidden email]> wrote:
the reason to do this is because i need to query the database quering date fields, the fields in the database are in this format 
2012-08-28 13:18:41.816, im using jquery ui datapicker to get the date value but when i try to run the query i get no result, i was thinking the reason is because the format are not the same... that why i want to save date values in this format yyyy-DD-mm... 

any suggestion

thanks again







2012/8/28 Sergio Michels <[hidden email]>
In the persistence the date will be parsed for the format that MySQL needs. Formatting dates should be responsibility of the presentation.

Also, in beforeUpdate you set the "dateCreated", is this correct or should it be beforeInsert?

If I'm not mistaken, if you define "dateCreated" and / or "lastUpdated" Grails will handle this fields for you.



On Tue, Aug 28, 2012 at 3:09 PM, chichibek bros <[hidden email]> wrote:
thanks Octavian Covalschi  but why is the reason for this warning!


2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks










Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

sergiomichels
I mean that it have to be different dates because you store the minutes and seconds in the database. If date1 and date2 is the same, no results will return. But if date1 and date2 are different dates and none of them is not null the query should work in the example that you transform to date.


On Tue, Aug 28, 2012 at 5:36 PM, chichibek bros <[hidden email]> wrote:
yes it can be differents dates


2012/8/28 Sergio Michels <[hidden email]>
In your previous post I can see that you store a date with minutes and seconds. date1 and date2 have different dates?


On Tue, Aug 28, 2012 at 5:14 PM, chichibek bros <[hidden email]> wrote:
this is the hql
def domainInstanceList = Request.findAll('from Request as r where r.dateAnswer between :d1 and :d2',[d1:params.date1,d2:params.date2])

this way i get this error message 
java.lang.String cannot be cast to java.util.Date

params.date1 and params.date2 are values from a jquery ui datepicker whit this format 

$("#date1").datepicker({dateFormat: 'yy-mm-dd'});
$("#date2").datepicker({dateFormat: 'yy-mm-dd'});

this was my fist problem pass from string to date i found some information to do this using parse method

def date1 = new Date().parse("yyyy-MM-dd", params.date1)
def date2 = new Date().parse("yyyy-MM-dd", params.date2)

its work it convert String to Date but the result of the query is always empty



2012/8/28 Sergio Michels <[hidden email]>
Can you post your query?


On Tue, Aug 28, 2012 at 4:42 PM, chichibek bros <[hidden email]> wrote:
the reason to do this is because i need to query the database quering date fields, the fields in the database are in this format 
2012-08-28 13:18:41.816, im using jquery ui datapicker to get the date value but when i try to run the query i get no result, i was thinking the reason is because the format are not the same... that why i want to save date values in this format yyyy-DD-mm... 

any suggestion

thanks again







2012/8/28 Sergio Michels <[hidden email]>
In the persistence the date will be parsed for the format that MySQL needs. Formatting dates should be responsibility of the presentation.

Also, in beforeUpdate you set the "dateCreated", is this correct or should it be beforeInsert?

If I'm not mistaken, if you define "dateCreated" and / or "lastUpdated" Grails will handle this fields for you.



On Tue, Aug 28, 2012 at 3:09 PM, chichibek bros <[hidden email]> wrote:
thanks Octavian Covalschi  but why is the reason for this warning!


2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks











Reply | Threaded
Open this post in threaded view
|

Re: how to persist a Date in a legacy database format

chichibek bros
Thanks Sergio, i will refactor the code im getting in as we (friends) say this a 'capa 8' problem, this mean the problem is between the chair and the keyboard

;) 

2012/8/28 Sergio Michels <[hidden email]>
I mean that it have to be different dates because you store the minutes and seconds in the database. If date1 and date2 is the same, no results will return. But if date1 and date2 are different dates and none of them is not null the query should work in the example that you transform to date.



On Tue, Aug 28, 2012 at 5:36 PM, chichibek bros <[hidden email]> wrote:
yes it can be differents dates


2012/8/28 Sergio Michels <[hidden email]>
In your previous post I can see that you store a date with minutes and seconds. date1 and date2 have different dates?


On Tue, Aug 28, 2012 at 5:14 PM, chichibek bros <[hidden email]> wrote:
this is the hql
def domainInstanceList = Request.findAll('from Request as r where r.dateAnswer between :d1 and :d2',[d1:params.date1,d2:params.date2])

this way i get this error message 
java.lang.String cannot be cast to java.util.Date

params.date1 and params.date2 are values from a jquery ui datepicker whit this format 

$("#date1").datepicker({dateFormat: 'yy-mm-dd'});
$("#date2").datepicker({dateFormat: 'yy-mm-dd'});

this was my fist problem pass from string to date i found some information to do this using parse method

def date1 = new Date().parse("yyyy-MM-dd", params.date1)
def date2 = new Date().parse("yyyy-MM-dd", params.date2)

its work it convert String to Date but the result of the query is always empty



2012/8/28 Sergio Michels <[hidden email]>
Can you post your query?


On Tue, Aug 28, 2012 at 4:42 PM, chichibek bros <[hidden email]> wrote:
the reason to do this is because i need to query the database quering date fields, the fields in the database are in this format 
2012-08-28 13:18:41.816, im using jquery ui datapicker to get the date value but when i try to run the query i get no result, i was thinking the reason is because the format are not the same... that why i want to save date values in this format yyyy-DD-mm... 

any suggestion

thanks again







2012/8/28 Sergio Michels <[hidden email]>
In the persistence the date will be parsed for the format that MySQL needs. Formatting dates should be responsibility of the presentation.

Also, in beforeUpdate you set the "dateCreated", is this correct or should it be beforeInsert?

If I'm not mistaken, if you define "dateCreated" and / or "lastUpdated" Grails will handle this fields for you.



On Tue, Aug 28, 2012 at 3:09 PM, chichibek bros <[hidden email]> wrote:
thanks Octavian Covalschi  but why is the reason for this warning!


2012/8/28 Octavian Covalschi <[hidden email]>
You should not do this. Just format it when you are displaying it...either in your web app or mysql client...


On Tue, Aug 28, 2012 at 10:55 AM, chichibek bros <[hidden email]> wrote:
hi group, i want to save a Date into a mysql database format yyyy-MM-dd i tried this

def  beforeUpdate() {
    dateCreated = dateCreated.format('yyyy-MM-dd')
}

any suggestion

Thanks