FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


What date format do you prefere with MySQL?





JayBee
I have found that there is many ways
Code:
DATE
DATETIME
TIMESTAMP
TIME
YEAR
INT (as unix time)
VARCHAR (as string :-D  "01/01/2007")


What format do you use?

I have mass in my projects so I want to decide for one of these Wink
Jamatu
INT (as unix time) all the way, I use that then just parse the output to a format I prefer.
goansfr
same to me. it's universal and no need to recreate function for converting date.
rohan2kool
INT rocks!! There are two reasons for it. most of the timestamps in other languages don't match the timestamp used MySQL. so you need to parse the timestamp that adds to the processing time and inconvinience. At the same time, it is difficult to customize the TIMESTAMP according to your wishes.

I use MySQL only with php, so i use the timestamp in php using the time() function and then store it. It is much better as you can perform arithmetic operations as and when the data is extracted.
snowboardalliance
Jamatu wrote:
INT (as unix time) all the way, I use that then just parse the output to a format I prefer.


Yeah, I work with the time in php so this is seamless.
Ducksteina
I use Timestamp. Why? Because I can easily add seconds to match the time zone I want to have. Also, parsing / formatting is very easy.

<3 Timestamp Smile
roeenoy
VARCHAR.
VARCHAR is the simple one because you can use like this:

(if log is VARCHAR):

$t = date(d/m/y);
mysql_query("insert into tbl (log) values('$t')");
choeirule
Well, it actually depend s on your needs ...
but i think the most flexible is using INT (as unix time)
cause you can parse it as you needs right?


am i just repeating?
Stubru Freak
I'm using DATE, just because it's meant for it (stupid reason I know)

And i extract it this way:
SELECT UNIX_TIMESTAMP(`Date`) AS `Date`
JayBee
roeenoy wrote:
VARCHAR.
VARCHAR is the simple one because you can use like this:

(if log is VARCHAR):

$t = date(d/m/y);
mysql_query("insert into tbl (log) values('$t')");


but you cant do this (you can do this, but it is a stupid idea Wink )

Code:
SELECT * FROM tbl ORDER BY log

so you must order it by ID or believe, that it is ordered automaticly by SQL server
Rank-1
depends... date or timestamp
ginny2689
i'm asking you a question in reply.

i'm new in php. So, don't know much about it .Please help me.

Can someone tell me the php code so that i will get the output like this
Sunday,18 march 2008
rvec
http://nl3.php.net/manual/en/function.date.php

Code:

<?php
echo date("l, d F o");

?>


That is if you want the current time.
ashok
I prefer DateTime, and use PHP's NOW() to insert the date. While extracting, I use date() to format the date according to my needs... Not much processing power required for this, i believe.
rvec
now() is mysql Wink

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
they also have a date() like php, but now() is mysql only for all i know.
Liu
unix time stamp format, much easier to convert to anything you want with it. However, if you know you're only going to be using one format for your apps, it's probably best to use that specific format.
imagefree
how to convert a date and time to INT so that it is easily convertible into date format later.
rvec
imagefree wrote:
how to convert a date and time to INT so that it is easily convertible into date format later.

to INT?
just
$time = (int) $time;

But I am guessing you mean linux timestamp.
http://nl3.php.net/manual/en/function.mktime.php
read through that Wink
imagefree
rvec wrote:
imagefree wrote:
how to convert a date and time to INT so that it is easily convertible into date format later.

to INT?
just
$time = (int) $time;

But I am guessing you mean linux timestamp.
http://nl3.php.net/manual/en/function.mktime.php
read through that Wink


Thanks rvec for the sample code you provided.

I totally confused using the link you provided.
I cant understand the date system of php. However only thing i understood is that php starts counting from 1970. Am i rite?

Here is how I reached this conclusion:


Code:
<?php

$time=time();           // This gives a lonnnnnnnnnnng integer.
$hours=floor($time/3600);     // This divides the integer by 3600 and convers it to complete hours.
$days=floor($hours/24);       // It converts the integer to number of days.
$years=floor($days/365);       // It converts integer to years.

echo $hours. "<br>";
echo $days . "<br>";
echo $years . "<br>";
echo date('Y')-$years;         //By deducting the current time from the current date, i returns 1970!
//Means the counting of years started from 0000 while the counting of seconds started from 1970.

//echo (INT)time()."\n\n\n";
//echo (INT)date("M-d-Y", mktime(0, 0, 0, 12, 32, 1997));
//echo  "\n
//".date('d-m-y');

?>




Output


Code:
334939
13955
38
1970


If i have reached it correctly, i think i have found the solution of the question i asked above.

I used the echo mktime(0, 0, 0, 1, 1, 1998); but it returns 883594800 what is it?
rvec
that's the linux timestamp. It's the time in seconds since the epoch (1st Jan 1970).
AOP Web Development
could you guys give a sample uses why you prefer to choose timestamp? or int(unix) ?
coz me i only use date or datetime as my date format in mysql
ginny2689
rvec wrote:
http://nl3.php.net/manual/en/function.date.php

Code:

<?php
echo date("l, d F o");

?>


That is if you want the current time.


Sir will this current time display of the country where my website is seeing by someone or mine country from where i hosted my website???
rvec
it will display the server time. So it doesn't matter who is looking at the site or who is the owner of the site.
Peterssidan
I use INT to store dates if I need a timestamp. It's not always best in all situations but work very often. If the time is before 1970 it has to be stored in another way but thats rare.
ginny2689
rvec wrote:
it will display the server time. So it doesn't matter who is looking at the site or who is the owner of the site.


Sir is there any way if we want to display that person time who is seeing our website .
manav
DateTime with NOW() to insert and date() to extract
rvec
ginny2689 wrote:
rvec wrote:
it will display the server time. So it doesn't matter who is looking at the site or who is the owner of the site.


Sir is there any way if we want to display that person time who is seeing our website .

http://www.willmaster.com/library/javascript/determining-your-visitors-time-zone.php
With that you can Smile
Related topics
PHP date() format for atom in php 4
Help with mysql query
What is the best way to save a date/timestamp in mysql
problem in saving and retrieving data in longtext format
Format date come from database!
Simple php & mysql script
displaing the date
miliseconds to normal date
How can I check...
Windows date
Best time/date format on websites
MySQL dates
Correct Date Format for a Google Sitemap
Checkbox and Date filter with mysql and PHP
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.