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 
INT (as unix time) all the way, I use that then just parse the output to a format I prefer.
same to me. it's universal and no need to recreate function for converting date.
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.
| 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.
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 
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')");
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?
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`
| 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
)
| Code: |
| SELECT * FROM tbl ORDER BY log |
so you must order it by ID or believe, that it is ordered automaticly by SQL server
depends... date or timestamp
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
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.
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.
now() is mysql
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.
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.
how to convert a date and time to INT so that it is easily convertible into date format later.
| 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 
| 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  |
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?
that's the linux timestamp. It's the time in seconds since the epoch (1st Jan 1970).
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
| 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???
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.
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.
| 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 .
DateTime with NOW() to insert and date() to extract
| 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 