Subject Re: [firebird-support] Context variables
Author Ivan Prenosil
>> > Am I correct in thinking that these are equivalent line of code (given both
>> > dt1 & dt2 are defined as date (dialect1) and timestamp (dialect3):
>> >
>> > dt1 = CURRENT_TIMESTAMP;
>> >
>> > dt2 = CAST(CAST ('NOW' AS VARCHAR(11)) as DATE);
>>
>> No.
>
> Thanks for the response:
>
>> * First one will return timestamp (i.e. date+time),
>> the second one just date.
>
> I understand that in dialect 3 but in dialect 1 I thought they would produce the
> same

Yes, in dialect 1 both produce full timestamp value.


>> * First one is evaluated only once for each statement,
>> the second one everytime the expression is evaluated.
>
> understood
>
>> * 'NOW' is CHAR(3) string, there is no reason to cast it to VARCHAR(11).
>> This is enough:
>> dt2 = CAST('NOW' as DATE);
>
> for dialect 1, I thought I was getting the date (NOW), chopping off the time
> portion (varchar 11) and then making it into a date again

This is CHAR(3) string whose value is 'NOW':
'NOW'

This will produce VARCHAR(11) string whose value is still 'NOW':
CAST ('NOW' AS VARCHAR(11)

This will just convert string 'NOW' either DATE (in dialect 3)
or full TIMESTAMP, including time (in dialect 1):
CAST(CAST ('NOW' AS VARCHAR(11)) as DATE)

To strip-off time portion from timestamp, you have to convert
string 'NOW' to timestamp, get first 11 characters,
then convert it back. This will work in both dialects:
CAST(CAST(CAST ('NOW' AS DATE) AS VARCHAR(11)) AS DATE)

Ivan
http://www.volny.cz/iprenosil/interbase/