|
-
Dec 1st, 2002, 05:07 PM
#1
Thread Starter
Frenzied Member
Get the Date & Time From A MySQL Time Stamp? -Solved[:)]-
OK, now if i create a record in my table, (mysql) i have a timestamp field, so it fills in like:
20021201214855
Translated To:
Date: 01 December 2002
Time: 21:48:55
Now, i know its in the form:
YearMonthDayHourMinuteSecond
But, is there a way (Already made) That will make it into an easy to read manner?
And if i can split it into the actual Date & Time seperate, Cool
Last edited by wpearsall; Dec 2nd, 2002 at 05:57 PM.
Wayne
-
Dec 1st, 2002, 09:30 PM
#2
Stuck in the 80s
Use the Date() function:
Code:
Date('d m Y', $time_stamp_here)
-
Dec 1st, 2002, 09:57 PM
#3
Thread Starter
Frenzied Member
Doesn't seam to do the trick?
20021201214855 -> 19 01 2038
using:
PHP Code:
Date('d m Y',$lutimestamp)
& Using:
PHP Code:
Date('d m Y',"20021201214855")
Tnx,
-
Dec 1st, 2002, 10:07 PM
#4
Thread Starter
Frenzied Member
Don't Spose theres a Left$() + Right$() Function in php?
-
Dec 1st, 2002, 11:36 PM
#5
Stuck in the 80s
It should work fine...
No, there is no Left() or Right(). Use the substr() function.
-
Dec 1st, 2002, 11:50 PM
#6
Stuck in the 80s
Are you misunderstanding the format of a unix timestamp? I don't know much about them, so I'm not sure, but when I run this code:
Code:
echo mktime(11, 41, 11, 12, 1, 2002);
I get '1038760871' for the timestamp.
-
Dec 2nd, 2002, 04:39 AM
#7
Thread Starter
Frenzied Member
Oh, it isn't on a *nix system,
It's on a Win2k Pro SP3 Server.
I Will Test The date() Thing On My Hosted Server L8r.
Are you misunderstanding the format of a unix timestamp?
Im not certain, This is the TimeStamp field for a MySQL Database Feild,
I am importing a CSV File regularly, & want to b able to get the time the file was imported, without altering the file to add the time to 200 + records manually.
PHP Code:
echo mktime(11, 41, 11, 12, 1, 2002);
Say What? (Little Lost @ This?)
Use the substr() function
OK, will look @ The manual 4 this when i get bk from college, split the date & Time from the stamp manually if all else fails.
-
Dec 2nd, 2002, 07:03 AM
#8
Stuck in the 80s
You don't have to be on a unix system to use a unix timestamp.
And as far as I know, they are the only kind of timestamps used by PHP and MySQL. Anyone who knows better, feel free to ring in now.
The mktime() function returns a unix timestamp based on the date you give it:
Code:
echo mktime(HOUR, MINUTE, SECOND, MONTH, DAY, YEAR);
-
Dec 2nd, 2002, 07:05 AM
#9
Stuck in the 80s
And you are right about the format of the timestamp, according to http://www.mysql.com/doc/en/DATETIME.html
I'm not sure why that function doesn't create it in that format. I suppose UNIX Timestamps are different than MySQL Timestamps afterall?
-
Dec 2nd, 2002, 05:55 PM
#10
Thread Starter
Frenzied Member
OK, got the substr function down too now (Bonus or what )
So i got the date & Time Like:
PHP Code:
<?php
// Date - Day / Month / Year
echo substr($lutimestamp, 6,2)."/".substr($lutimestamp, 4,2)."/".substr($lutimestamp, 0,4);
?>
<?php
// Time - Hour:Minute
echo substr($lutimestamp, 8,2).":".substr($lutimestamp, 10,2);
?>
and seams to work kool,
-
Dec 2nd, 2002, 06:04 PM
#11
Thread Starter
Frenzied Member
Originally posted by The Hobo
You don't have to be on a unix system to use a unix timestamp.
And as far as I know, they are the only kind of timestamps used by PHP and MySQL. Anyone who knows better, feel free to ring in now.
The mktime() function returns a unix timestamp based on the date you give it:
Code:
echo mktime(HOUR, MINUTE, SECOND, MONTH, DAY, YEAR);
Little extra note with this,
So, if i decided to [not sure yet but probally will] make a forum, to go wiv the portal / site im buildin now,
When i add the date the post's are made the the database,
I add it like:
PHP Code:
mktime(date("h"), date("i")...
and then i can get it back to normal, With the users setting of the date / time by the:
PHP Code:
date($user_format, $post_time);
Correct?
: BTW, when u fink that vbsboard will have a public release,
: Cuz their comin on well,
-
Dec 2nd, 2002, 06:44 PM
#12
Stuck in the 80s
Originally posted by wpearsall
When i add the date the post's are made the the database,
I add it like:
PHP Code:
mktime(date("h"), date("i")...
Actually (don't know why I didn't use this before), do this:
Should give you the correct timestamp.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|