User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 455,962 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,578 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 1092 | Replies: 7 | Solved
Reply
Join Date: Oct 2007
Posts: 188
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

selecting the day from the DATE field so that it includes a zero...

  #1  
Nov 13th, 2007
Is it possible to select day from the DATE field in a db so that it includes a zero in front of it if the day is less than 10?

If so could you post the code please.

Struggling and stressed...with qwerty imprinted on my forehead
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: selecting the day from the DATE field so that it includes a zero...

  #2  
Nov 13th, 2007
You need to first convert the date to a php format. So we use the strtotime() function.

<?php
$date = "2007-11-13"; (or from DB)
$date = strtotime($date);
$aday = date("l",$date);

//Then we will pad zeros.

$paddedDays = str_pad($aday, 2, "0",STR_PAD_LEFT);
echo $paddedDays ;
?>

Let me know how it goes.
Last edited by binoj_daniel : Nov 13th, 2007 at 1:00 pm.
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: selecting the day from the DATE field so that it includes a zero...

  #3  
Nov 13th, 2007
Or, to use the MySQL functions, you could do ...

mysql> select date_format("2007-1-1","%Y-%m-%d");
+------------------------------------+
| date_format("2007-1-1","%Y-%m-%d") |
+------------------------------------+
| 2007-01-01                         |
+------------------------------------+
1 row in set (0.25 sec)

Then the solution is more general, and could be used if you were using Perl or PHP or whatever.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Oct 2007
Posts: 188
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Re: selecting the day from the DATE field so that it includes a zero...

  #4  
Nov 14th, 2007
Thanks for the help

Much appreciated
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: selecting the day from the DATE field so that it includes a zero...

  #5  
Nov 14th, 2007
Originally Posted by Venom Rush View Post
Thanks for the help

Much appreciated


Did it work for you?
Reply With Quote  
Join Date: Oct 2007
Posts: 188
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Re: selecting the day from the DATE field so that it includes a zero...

  #6  
Nov 15th, 2007
Originally Posted by binoj_daniel View Post
Did it work for you?

Didn't try it out, managed to sort my problem out with some php code.
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: selecting the day from the DATE field so that it includes a zero...

  #7  
Nov 15th, 2007
What php code did you try?
Reply With Quote  
Join Date: Oct 2007
Posts: 188
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Re: selecting the day from the DATE field so that it includes a zero...

  #8  
Nov 15th, 2007
Used this for putting the date back into the db so I didn't actually need to pull it out with the zero.

  1. if ($_GET['startDay'] = $row[0]) {
  2. $day = $_GET['startDay'];
  3. if ($day < 10) {
  4. $startDay = "0".$day;
  5. } else {
  6. $startDay = $_GET['startDay'];
  7. }
  8. } else {
  9. $startDay = $_POST['startDay'];
  10. }
Last edited by Venom Rush : Nov 15th, 2007 at 11:35 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 9:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC