Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Inserting Birthday in Database?

Posted on 2009-05-13
10
Medium Priority
?
312 Views
Last Modified: 2012-05-06
I am creating a very simple table which will consist of Users Birtday (month and day only)
i created a Table
create 2 col.
Username  type varchar
Bday type Datetime

now on ASP side i need to be able to insert the birthday to DB.
so i created 3 dropdownlist
1-User 2-Month 3-Day
all of them are populated .

now here is my problem not sure how i can insert it into DB as a DateTime format ... my goal is i need to be able to insert it and then write a simple SQL to show me all upcoming Birthdays for the next month.

Thank you,
0
Comment
Question by:Raul77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24377245
Hello Raul77,

if you dont want to put the year, use to differernt columns to store the Month and day, you can query the upcoming birth days by using

SELECT *
FROM urTable
WHERE MONTH (Getdate() ) = dobMonth

Regards,

Aneesh
0
 

Author Comment

by:Raul77
ID: 24377291
Hello Aneesh
thanks for the help ,
so i need to create 2 col. in DB , should they be type datetime?

btw i am using MSSQL 2000.

and in case you are wondering this is how i populate my dropdownlist

 DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
        for (int month = 1; month < 13; month++)
        {
            ListItem li = new ListItem();
            li.Text = dtfi.GetMonthName(month);
            li.Value = month.ToString();
            ddlMonth.Items.Add(li);
        }
        for (int i = 1; i < 32; i++)
        {
            ListItem day = new ListItem();
            day.Text = i.ToString();
            day.Value = i.ToString();
            ddlDay.Items.Add(day);
        }

Open in new window

0
 

Author Comment

by:Raul77
ID: 24380488
anyone else has any idea on this?

thanks, i can re-design the table if need be.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24380511
You can use a TinyInt for  these , tiny int can store upto 255
0
 

Author Comment

by:Raul77
ID: 24380525
Aneesh:
i have a few problem
1-) i would need 2 months in advanced to show ( previosuly stated 1)
2-) what if todays date is 11/23 2 months in advance with be 11/23 ... how can it know that?
also wouldnt the DAY start playing a role?

if its 11/23 , i dont want to see someones birthday if its on 1/28 ! or if it has passed.

Thanks for the help.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24380562

DECLARE @Day tinyint,
@Month tinyint
-- for current month
SELECT NAme, dob_Day, dob_Month
FROM urDOBTable
WHERE dob_day > @day and dob_month = @month
UNION ALL
SELECT NAme, dob_Day, dob_Month --- nextMonth
FROM urDOBTable
WHERE dob_month = CASE WHEN @month =12 THEN 1 ELSE @month END
0
 

Author Comment

by:Raul77
ID: 24386508
thanks Aneesh,
we are almost there, since i need the next 2 months i modified your script abit however now i am getting 2 table, we need to union ALL selects in 1 table

Thanks,

SELECT username, Bday, Bmonth
FROM users
WHERE Bday > 14 and Bmonth = 5
UNION ALL
SELECT username, Bday, Bmonth --- nextMonth
FROM users
WHERE Bmonth = CASE WHEN 5 =12 THEN 1 ELSE 6 END

SELECT username, Bday, Bmonth
FROM users
WHERE Bday < 14 and Bmonth = 7

SELECT username, Bday, Bmonth
FROM users
WHERE Bday > 14 and Bmonth = 5
UNION ALL
SELECT username, Bday, Bmonth --- nextMonth
FROM users
WHERE Bmonth = CASE WHEN 5 =12 THEN 1 ELSE 6 END
 
SELECT username, Bday, Bmonth
FROM users
WHERE Bday < 14 and Bmonth = 7

Open in new window

0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 24386625
here you go
 

 

DECLARE @Day tinyint, 
@Month tinyint 
-- for current month 
SELECT UserName, BDay, Bmonth 
FROM Users 
WHERE BDay > @day and Bmonth = @month 
UNION ALL 
SELECT UserName, BDay, Bmonth --- nextMonth 
FROM Users 
WHERE Bmonth = CASE WHEN @month =12 THEN 1 ELSE @month+1 END
UNION ALL 
SELECT UserName, BDay, Bmonth --- nextMonth 
FROM Users 
WHERE Bmonth = CASE WHEN @month =11 THEN 1 
					WHEN @Month =12 THEN 2 
					ELSE @month+2 END

Open in new window

0
 

Author Comment

by:Raul77
ID: 24386637
i added union and it seem to be working :) thank you Sir.
0
 

Author Closing Comment

by:Raul77
ID: 31581095
Thank you,
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this article, we’ll look at how to deploy ProxySQL.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question