Naija Ryders

Go Back   Naija Ryders > Main > Techie Forum
Connect with Facebook
Register Blogs FAQ Members List Guitar Hero Calendar Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 03-13-2008, 09:14 PM   #1 (permalink)
The 4 Eyed Monk.
 
maestro's Avatar
 
Join Date: Oct 2005
Location: Abuja, Nigeria
Posts: 41,510
Points: 100,113,253.22
Bank: 176.10
Total Points: 100,113,429.32
Donate
Blog Entries: 1
Rep Power: 2470000000 maestro has disabled reputation



Default PHPMySql help

Ok...

I I want to convert date coming from my mysql database i.e 2008-02-01, lets say to date in plane english i.e Feb 2nd, 2008.
I have tried all the dateTime functions I could find, but all they do is return the current date for all the entries, even though they are different.

What is the solution?
Thanks
__________________
maestro is offline   Reply With Quote
Old 03-13-2008, 09:26 PM   #2 (permalink)
Sir Lancelot
Tribunus Militum Consulari Potestate
 
Bubus's Avatar
 
Join Date: Sep 2001
Location: Germantown, MD
Posts: 42,206
Points: 3,251,220.41
Bank: 410,884,410.16
Total Points: 414,135,630.57
Donate
Rep Power: 21474942 Bubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legend



Default

Code:
This is for date format like March 10, 2008


Code:
// Assuming today is: March 10th, 2001, 5:16:18 pm

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-M-y, it is w Day z ');  // 05-16-17, 10-Mar-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:17 m is month
$today = date("H:i:s");                         // 17:16:17
?> 

__________________

Member: T-CAN, P-WAN, APPN, NGBC, CoHE, CDC
No disrespectfulness or bitchassness shall be tolerated.
Bubus is offline   Reply With Quote
Old 03-13-2008, 09:31 PM   #3 (permalink)
The 4 Eyed Monk.
 
maestro's Avatar
 
Join Date: Oct 2005
Location: Abuja, Nigeria
Posts: 41,510
Points: 100,113,253.22
Bank: 176.10
Total Points: 100,113,429.32
Donate
Blog Entries: 1
Rep Power: 2470000000 maestro has disabled reputation



Default

Quote:
Originally Posted by Bubus
Code:
This is for date format like March 10, 2008


Code:
// Assuming today is: March 10th, 2001, 5:16:18 pm

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-M-y, it is w Day z ');  // 05-16-17, 10-Mar-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:17 m is month
$today = date("H:i:s");                         // 17:16:17
?> 

Appreciate the help...but problem is, as U can see, that code returns the current date for that day...I dnt want that, just want to format the date in "d-m-y" to english
__________________
maestro is offline   Reply With Quote
Old 03-13-2008, 09:34 PM   #4 (permalink)
Sir Lancelot
Tribunus Militum Consulari Potestate
 
Bubus's Avatar
 
Join Date: Sep 2001
Location: Germantown, MD
Posts: 42,206
Points: 3,251,220.41
Bank: 410,884,410.16
Total Points: 414,135,630.57
Donate
Rep Power: 21474942 Bubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legend



Default

So heres your function...
Lets say your database stores your date "2008-02-01" in the string $date

heres what you do:

PHP Code:
<?php
    
list($year$month$day) = split("-"$date);
    
$date date('j-M-y'mktime(000$month$day$year));
    echo 
$date;
?>
__________________

Member: T-CAN, P-WAN, APPN, NGBC, CoHE, CDC
No disrespectfulness or bitchassness shall be tolerated.
Bubus is offline   Reply With Quote
Old 03-13-2008, 09:40 PM   #5 (permalink)
The 4 Eyed Monk.
 
maestro's Avatar
 
Join Date: Oct 2005
Location: Abuja, Nigeria
Posts: 41,510
Points: 100,113,253.22
Bank: 176.10
Total Points: 100,113,429.32
Donate
Blog Entries: 1
Rep Power: 2470000000 maestro has disabled reputation



Default

Quote:
Originally Posted by Bubus
So heres your function...
Lets say your database stores your date "2008-02-01" in the string $date

heres what you do:

PHP Code:
<?php
    
list($year$month$day) = split("-"$date);
    
$date date('j-M-y'mktime(000$month$day$year));
    echo 
$date;
?>
why are we splitting the original date strings?
__________________
maestro is offline   Reply With Quote
Old 03-13-2008, 09:41 PM   #6 (permalink)
The 4 Eyed Monk.
 
maestro's Avatar
 
Join Date: Oct 2005
Location: Abuja, Nigeria
Posts: 41,510
Points: 100,113,253.22
Bank: 176.10
Total Points: 100,113,429.32
Donate
Blog Entries: 1
Rep Power: 2470000000 maestro has disabled reputation



Default

This isnt a solution
__________________
maestro is offline   Reply With Quote
Old 03-13-2008, 09:46 PM   #7 (permalink)
Sir Lancelot
Tribunus Militum Consulari Potestate
 
Bubus's Avatar
 
Join Date: Sep 2001
Location: Germantown, MD
Posts: 42,206
Points: 3,251,220.41
Bank: 410,884,410.16
Total Points: 414,135,630.57
Donate
Rep Power: 21474942 Bubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legend



Default

Quote:
Originally Posted by maestro
why are we splitting the original date strings?
You want to convert 2008-02-01 to the format 01-Feb-08
First you split (using the "-" as separator), so you get the composite date components in
$year, $month, and $day.

Then you call mktime() to convert those composites into time.
You call date() to format that time into the new format j-M-y.

__________________

Member: T-CAN, P-WAN, APPN, NGBC, CoHE, CDC
No disrespectfulness or bitchassness shall be tolerated.
Bubus is offline   Reply With Quote
Old 03-13-2008, 09:47 PM   #8 (permalink)
Sir Lancelot
Tribunus Militum Consulari Potestate
 
Bubus's Avatar
 
Join Date: Sep 2001
Location: Germantown, MD
Posts: 42,206
Points: 3,251,220.41
Bank: 410,884,410.16
Total Points: 414,135,630.57
Donate
Rep Power: 21474942 Bubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legendBubus is a legend



Default

PHP Code:
 <?php
list($year$month$day) = split("-"$date);
$date date('M d, Y'mktime(000$month$day$year));
?>
This is for converting to format

Feb 01, 2008.
__________________

Member: T-CAN, P-WAN, APPN, NGBC, CoHE, CDC
No disrespectfulness or bitchassness shall be tolerated.
Bubus is offline   Reply With Quote
Old 03-13-2008, 09:52 PM   #9 (permalink)
The 4 Eyed Monk.
 
maestro's Avatar
 
Join Date: Oct 2005
Location: Abuja, Nigeria
Posts: 41,510
Points: 100,113,253.22
Bank: 176.10
Total Points: 100,113,429.32
Donate
Blog Entries: 1
Rep Power: 2470000000 maestro has disabled reputation



Default

works not
__________________
maestro is offline   Reply With Quote
Old 03-14-2008, 01:09 AM   #10 (permalink)
Captain
 
Join Date: Jul 2001
Location: Retirement
Posts: 21,057
Points: 181,575.00
Bank: 848,419,240.83
Total Points: 848,600,815.83
Donate
Rep Power: 21474900 Uncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legend
Default

PHP is a little complicated as php deals with dates in the UNIXTIMESTAMP form so you have to convert to that before you can format it in php.

I have a couple solutions:
Sol 1: Here is are pure mysql solution.


If the column datatype is date try this:

PHP Code:
SELECT *, date_format(your_date_column'%M %d, %Y, %l:%i%p') AS newdate FROM your_table
and in your loop print $yourrow['newdate'] where ever you want.

2. MySQL has a function to convert any time of timeand date or date datatype column into a unix timestamp for you.
Use SELECT * UNIX_TIMESTAMP(your_date_column) FROM `timeanddate`

and then use the php date function to convert the date to the desired format.
For neatness, i like to use aliases.
e.g.
PHP Code:
SELECT UNIX_TIMESTAMP(your_date_column) AS newdate FROM `timeanddate
then in php, simply..
PHP Code:
$unixformateddate $yourrow['newdate']

$prettydatedate("j-M-y",$unixformateddate);

print 
$prettydate
Oila!
Give this a shot. It should work. I tried the MySql part.
__________________
"A small stone may only make a small ripple at first, but someday it will be a wave." -Wiegraf, FFT


NR Tribalists, Religious Bigots, and Enemies of Progress: Your name Here?


Beat the U.S. Financial Crisis
Uncle Sunday is offline   Reply With Quote
Old 03-14-2008, 01:52 AM   #11 (permalink)
The 4 Eyed Monk.
 
maestro's Avatar
 
Join Date: Oct 2005
Location: Abuja, Nigeria
Posts: 41,510
Points: 100,113,253.22
Bank: 176.10
Total Points: 100,113,429.32
Donate
Blog Entries: 1
Rep Power: 2470000000 maestro has disabled reputation



Default

The mysql part is on point!!
__________________
maestro is offline   Reply With Quote
Old 03-14-2008, 10:44 AM   #12 (permalink)
Captain
 
Join Date: Jul 2001
Location: Retirement
Posts: 21,057
Points: 181,575.00
Bank: 848,419,240.83
Total Points: 848,600,815.83
Donate
Rep Power: 21474900 Uncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legendUncle Sunday is a legend
Default

nice one
__________________
"A small stone may only make a small ripple at first, but someday it will be a wave." -Wiegraf, FFT


NR Tribalists, Religious Bigots, and Enemies of Progress: Your name Here?


Beat the U.S. Financial Crisis
Uncle Sunday is offline   Reply With Quote
Old 03-21-2008, 11:21 PM   #13 (permalink)
Registered User
 
edux2's Avatar
 
Join Date: Dec 2006
Location: On High Grounds
Posts: 7
Points: 101,339.19
Bank: 1,572.12
Total Points: 102,911.31
Donate
Rep Power: 0 edux2 is a legendedux2 is a legendedux2 is a legendedux2 is a legendedux2 is a legendedux2 is a legendedux2 is a legendedux2 is a legendedux2 is a legendedux2 is a legendedux2 is a legend
Exclamation I Need downloads

Bros can u pls help me with either AVG Latest edition or Avast antivirus with the crack. if u can help upload and send to edux2@yahoo.com. i need it badly
__________________
Neva offend Ur Fanz else u end up like :fancy: .
if u believe me then u dey Mental.
Above all
edux2 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Points Per Thread View: 0
Points Per Thread: 0
Points Per Reply: 0
Forum Jump


All times are GMT +2. The time now is 11:36 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
NaijaRyders