DATE problem

Reply

Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

DATE problem

 
0
  #1
Sep 30th, 2008
I Need to insert a date into mysql database i dont know which is better
using DATE or VARCHAR as the date field ??
im using now the DATE type but whenever i insert any date its not inserted in the DB
0000-00-00 it appears like this .

the Code:

$mydate=date("$year.$month.$day");

insert into ....values ($mydate);

i dont know what's wrong

plz help
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: DATE problem

 
0
  #2
Sep 30th, 2008
Originally Posted by yasmena View Post
I Need to insert a date into mysql database i dont know which is better
using DATE or VARCHAR as the date field ??
im using now the DATE type but whenever i insert any date its not inserted in the DB
0000-00-00 it appears like this .

the Code:

$mydate=date("$year.$month.$day");

insert into ....values ($mydate);

i dont know what's wrong

plz help
The dashes are required.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 234
Reputation: PoA is an unknown quantity at this point 
Solved Threads: 8
PoA PoA is offline Offline
Posting Whiz in Training

Re: DATE problem

 
0
  #3
Sep 30th, 2008
Replace dots with dashes. Try below.
  1. $mydate=date("$year-$month-$day");
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,076
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: DATE problem

 
0
  #4
Oct 1st, 2008
what error you got?????
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 31
Reputation: srilakshmitr7 is an unknown quantity at this point 
Solved Threads: 2
srilakshmitr7's Avatar
srilakshmitr7 srilakshmitr7 is offline Offline
Light Poster

Re: DATE problem

 
0
  #5
Oct 1st, 2008
I think there is problem in inserting the values into database can you once check the syntax of insert query or if you provide the query i will look into it
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 38
Reputation: kevindougans is an unknown quantity at this point 
Solved Threads: 1
kevindougans kevindougans is offline Offline
Light Poster

Re: DATE problem

 
0
  #6
Oct 1st, 2008
Regardless of what the error is I find it best to store a unix timestamp in the database in a "int" field and then use PHP to manipulate it.

This produces a very fast db table when sorting by date.

This is the best practice until you become more familiar with php and mysql and explore the differences in formatting the date.

To get the unix timestamp do something like:
  1. $unix_time = date('U');
you can then format this by doing:
  1. $formatted_time = date('Y-m-d',$unix_time);
  2.  
  3. $formatted_time_plus_1_week = date('Y-m-d',strtotime("+1 week",$unix_time));
Very simple.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

Re: DATE problem

 
0
  #7
Oct 1st, 2008
U know Thanks So much i solved the problem
but now i faced another
when the date is displayed its displayed YYYY-MM-DD
is their anyother way to display it as DD-MM-YYYY ?????????????????
if im storing as DATE
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 234
Reputation: PoA is an unknown quantity at this point 
Solved Threads: 8
PoA PoA is offline Offline
Posting Whiz in Training

Re: DATE problem

 
1
  #8
Oct 2nd, 2008
  1. $date = '2008-09-29';
  2. $newDate = date('d-m-Y', strtotime($date));
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

Re: DATE problem

 
0
  #9
Oct 2nd, 2008
Thank You Very Much POA
but may i ask why are u using
strtotime here ?? why not just say
$newDate=date('d-m-Y');
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: DATE problem

 
0
  #10
Oct 3rd, 2008
Originally Posted by yasmena View Post
Thank You Very Much POA
but may i ask why are u using
strtotime here ?? why not just say
$newDate=date('d-m-Y');
That would be fine if you just wanted today's date.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 714 | Replies: 9
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC