• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

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?
0
KKrui
Asked:
KKrui
  • 4
  • 3
  • 3
  • +2
1 Solution
 
dash420Commented:
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.

0
 
KKruiAuthor Commented:
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.
0
 
KKruiAuthor Commented:
can anyone has idea on it??
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
jamathonCommented:
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.
0
 
PaulmcCommented:
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.
0
 
KKruiAuthor Commented:
hi, jamathon. can u show me an example?
0
 
dash420Commented:
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.
0
 
dash420Commented:
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.
0
 
jamathonCommented:
hi, code should be something like this

using dd-mm-yyyy


<cfquery name="DOBcheck" datasource="profile" dbtype="ODBC">
select *
from Cust_info
order by cust_dob
</cfquery>



<cfloop query="DOBcheck">
<cfset birth_day=left(cust_dob,2)>
<cfset birth_month=left(right(cust_dob,7),2)>
<cfset this_year=dateformat(now(),'yyyy')
<cfset this_birthday=createdate(this_year,birth_month,birth_day)>
<cfif datediff('d',now(),this_birthday) eq 14>
put your condition here to add to list or array
</cfif>
</cfloop>


Probably best scheduled as an overnight task
0
 
jamathonCommented:
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
0
 
dash420Commented:
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>    
0
 
MoondancerCommented:
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:  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp  
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now