| | |
Format datetime to use with mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I need to format PHP to use with one of my date field (DATETIME).
I want to get current time and format it. I have checked some googled articles but I cannot get far.
Please help me!
I want to get current time and format it. I have checked some googled articles but I cannot get far.
Please help me!
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
In php use:
PHP Syntax (Toggle Plain Text)
$mydate = date('Y-m-d H:i:s'); //this will produce a date like 2009-09-20 17:44:09 $query = mysql_query("INSERT INTO mytable SET mydatefield = '{$mydate}', field2 = 'value2'");
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Dont format the date time in the database
text formatted dates are for humans to read, sql is not human does not need any of that and it makes the processing slower
sql Date, php date, unix timestamp, are all a single 10byte numeric that stores complete date and time
formatting is done for human readability on output
example
sql now() will input the date and time of the update as the update is processing
php date() is now
1253454900 (10bytes)
or
September 20 2009, 1:55pm (25bytes)
not much on 1 row, very much on a million rows
select * from table where date > 1234567890 and date < 1234568890
is much faster than precessing text dates
processing script languages have strtotime() (or an identical function) built in, you dont even have to do any text to time conversions on range select fields
text date time: not good
text formatted dates are for humans to read, sql is not human does not need any of that and it makes the processing slower
sql Date, php date, unix timestamp, are all a single 10byte numeric that stores complete date and time
formatting is done for human readability on output
example
<?php echo date('DMY h:m',$timestamp} ?> selecting a timestamp renage from num1 to num2 is much faster - less processing than searching text dates for dates between x and 1sql now() will input the date and time of the update as the update is processing
php date() is now
1253454900 (10bytes)
or
September 20 2009, 1:55pm (25bytes)
not much on 1 row, very much on a million rows
select * from table where date > 1234567890 and date < 1234568890
is much faster than precessing text dates
processing script languages have strtotime() (or an identical function) built in, you dont even have to do any text to time conversions on range select fields
text date time: not good
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
I'd agree with AB about now() in SQL - better than using date() first and then using it, but if you need the current date for output to screen as well as input to db, you may as well.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
•
•
•
•
Dont format the date time in the database
text formatted dates are for humans to read, sql is not human does not need any of that and it makes the processing slower
sql Date, php date, unix timestamp, are all a single 10byte numeric that stores complete date and time
formatting is done for human readability on output
example<?php echo date('DMY h:m',$timestamp} ?>selecting a timestamp renage from num1 to num2 is much faster - less processing than searching text dates for dates between x and 1
sql now() will input the date and time of the update as the update is processing
php date() is now
1253454900 (10bytes)
or
September 20 2009, 1:55pm (25bytes)
not much on 1 row, very much on a million rows
select * from table where date > 1234567890 and date < 1234568890
is much faster than precessing text dates
processing script languages have strtotime() (or an identical function) built in, you dont even have to do any text to time conversions on range select fields
text date time: not good
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
For Complete Date & time Statement in PHP with MySQL Please Go to:
http://in2.php.net/manual/en/function.date.php
The above will give u all your problem solution.
Thank You..
http://in2.php.net/manual/en/function.date.php
The above will give u all your problem solution.
Thank You..
Last edited by hemgoyal_1990; Sep 21st, 2009 at 3:56 am.
http://www.kuchamancity.com
Hem Web Solution..
Behind Every Successful Man, There is an Untold Pain in His Heart.
Hem Web Solution..
Behind Every Successful Man, There is an Untold Pain in His Heart.
•
•
•
•
For Complete Date & time Statement in PHP with MySQL Please Go to:
http://in2.php.net/manual/en/function.date.php
The above will give u all your problem solution.
Thank You..
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
http://www.kuchamancity.com
Hem Web Solution..
Behind Every Successful Man, There is an Untold Pain in His Heart.
Hem Web Solution..
Behind Every Successful Man, There is an Untold Pain in His Heart.
I solved it with gmdate()
php Syntax (Toggle Plain Text)
function getnow(){ //mysql date format -- 'YYYY-MM-DD HH:MM:SS' // Create the UNIX Timestamp, using the current system time $ptime = time(); // Convert that UNIX Timestamp into a string (GMT), safe for MySql -- GMT +3 $toffset = +3.00; $stime = gmdate("Y-m-d H:i:s", $ptime+$toffset * 3600); return $stime ; }
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
No dude(dudess?)
store the 10 digit timestamp in the database
convert to text on output
Mysql does not care what it looks like and it is faster smaller and simpler for mysql to process the numeric to search for records between 1 January and 1 March
the returned $time function is much larger than 10bytes
that function would be better in the script used output data to be human readable in reports
Store $ptime
$ptime 1234568888
$stime Monday 13 Feb 2009 10:55am
store the 10 digit timestamp in the database
convert to text on output
Mysql does not care what it looks like and it is faster smaller and simpler for mysql to process the numeric to search for records between 1 January and 1 March
the returned $time function is much larger than 10bytes
that function would be better in the script used output data to be human readable in reports
Store $ptime
$ptime 1234568888
$stime Monday 13 Feb 2009 10:55am
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
![]() |
Similar Threads
- Date Format PHP mysql (PHP)
- storing date mysql (PHP)
- Inserting date in format DD-MM-YYYY in MySQL (MySQL)
- Parsing a date into MM/DD/YYYY HH:MM:SS format (Python)
Other Threads in the PHP Forum
- Previous Thread: Email with attachment corrupts file
- Next Thread: How to protect my videos from downloading
| Thread Tools | Search this Thread |
action address ajax apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date dehasher display domain dynamic echo email error errorlog fatalerror file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla limit link load login mail malfunctioning masterthesis menu mlm multiple mysql nodes oop paypal pdf php popup problem query radio ram random record recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform youtube






