Link to home
Start Free TrialLog in
Avatar of KKrui
KKrui

asked on

check ur birthday

i need to implement a function which could check for customer birthday
let say i store the DOB in date format, dd-mmm-yyyy in database

i plan to use query to extract the birthday within two week, so
the query will be something like this:

<cfquery name="DOBcheck" datasource="profile" dbtype="ODBC">
select *
from Cust_info
where cust_dob-now() <= 14 AND cust_dob-now()> 0
order by cust_dob
</cfquery>

but the problem is the comparation is include "year"
if i just wanto compare using day and month,
like "1 Jul" display, since it is within condition range)

how the condition *** wil look like?
Avatar of dash420
dash420
Flag of Canada image

Hi
instead of using coldfusion function now(), use the sysdate of oracle if u are using oracle. it will solve ur problem.

<cfquery name="DOBcheck" datasource="profile" dbtype="ODBC">
select *
from Cust_info
where (cust_dob- to_date(sysdate,'dd-mon-yyyy') <= 14 )AND (cust_dob- to_date(sysdate,'dd-mon-yyyy') > 0)
order by cust_dob
</cfquery>

otherwise use dateformat of coldfusion before cust_dob variable. it will definitly work.

Avatar of KKrui
KKrui

ASKER

no, if just directly deduct from the date, it will definately not work.
just like if someone birthday was on 01-jul-1975
if compare with today's date, which is 30-jun-2001,
the different of time will be more than 14 days.

i just want it to compare the day's and month only, to display
those birthday which will be coming in two weeks time.
Avatar of KKrui

ASKER

can anyone has idea on it??
I think you need the query to return all customers, you can then loop through the resultset and perform string manipulation to change their DOB to their birthday this year and then use datediff.

If there are a lot of records you may be better to schedule the task to run when the server is quiet.
Have you tried using DateDiff to get the value you are looking for?

WHERE
#Abs(DateDiff('d', DateFormat("#cust_dob#","dd"), day(Now())))# <= 14
AND
#Abs(DateDiff('m', cust_dob, Now()))# > 0


Regards,

Paul.
Avatar of KKrui

ASKER

hi, jamathon. can u show me an example?
Hi KKrui

sorry for this delay. Actually u can't do directly through query rather u can check this through coldfusion.

code is like this


<cfquery name="qrytest" datasource="ebdb" debug="Yes">
    select date1 from temp
</cfquery>

<cfoutput query="qrytest">
   <cfif #datediff('d',day(Now()),dateformat(date1,"dd")) #lte 14
       and #evaluate( month(Now()) - month(date1) ) #  eq 0>
      #date1#</cfif>
</cfoutput>

it will print only the dateof birth 14 days beyonds current date.    

check with this code it will  work.
Hi KKrui

sorry for this delay. Actually u can't do directly through query rather u can check this through coldfusion.

code is like this


<cfquery name="qrytest" datasource="ebdb" debug="Yes">
    select date1 from temp
</cfquery>

<cfoutput query="qrytest">
   <cfif #datediff('d',day(Now()),dateformat(date1,"dd")) #lte 14
       and #evaluate( month(Now()) - month(date1) ) #  eq 0>
      #date1#</cfif>
</cfoutput>

it will print only the dateof birth 14 days beyonds current date.    

check with this code it will  work.
ASKER CERTIFIED SOLUTION
Avatar of jamathon
jamathon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you may find a flaw in dash420's code

It will only work when the current date and the database date are in the same month.

Also I neglected to close a tag in my code

Cheers
I forgot to think of that case when sysdate will end of the month so please change the last condition.

condition code is


<cfoutput query="qrytest">
<cfif #datediff('d',day(Now()),dateformat(date1,"dd"))#    lte 14
       and #evaluate( month(Now()) - month(date1) ) #   lte 1>
 
<!---put ur code here--->
/cfif>
</cfoutput>    
KKrui:

You have asked 11 questions within Experts Exchange and finalized (graded/awarded) zero of them.

_________________________________________________________

It's time to clean up this topic area and that means taking care of this question. Your options at this point are:
 
1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.
 
2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.
 
3.  Ask Community Support to help split points between participating experts.  Just comment here with details.
 
4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.
 
If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.  We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.
 
PLEASE DO NOT AWARD THE POINTS TO ME.
 
____________________________________________
 
 
 
Hi Experts:
 
In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.
 
Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question.
 
Thank you everyone.
 
Moondancer :)
Community Support Moderator @ Experts Exchange
 
P.S.  Engineering has been advised about the error in the comment date/time sort order.  REGARDING POINTS and more see this link please.  Easy questions begin at a recommended 50 points.  You can quickly and easily change the value of your open questions:  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp