If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > to insert DATE TO DB/TABLE, how must inserted the date , what format ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-19-08, 13:46
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
to insert DATE TO DB/TABLE, how must inserted the date , what format ?

When in phpMyAdmin I have

Field Type
dateplaced timestamp

then in a command like
Code:
	$datenow = time();	 
	//  $datenow = date("H:i j/m/y", $tsnow);  // p.516-7
	$status="PENDING";
	$email6=$_SESSION['email'];
	$query = "INSERT INTO $BookingsTable VALUES(NULL,'$datenow',0,'$email6','$status','$datep','$dated','$Locationp','$Locationd','$days','$mostdaysrate','$vat','$off','$finalprice','$cat')";
to insert DATE TO DB/TABLE, how must inserted the date , what format ?
I insert timestamp but appears(in BROWSE DATAELECT * FROM `bookings2` LIMIT 0 , 30)
0000-00-00 00:00:00 as field dateplaced ??? well, why appear zeros ?
Reply With Quote
  #2 (permalink)  
Old 10-19-08, 14:49
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Im confused here
..do you men PHPMyAdmin or PHP
timestamp is a reserved word
you only need to encapsulate text / string columns
usually dates should be in ISO format (yyyy/mm/dd @ hh:mm:ss)
the @ hh:mm:ss is optional

http://www.google.co.uk/search?hl=en...e+Search&meta=
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 10-19-08, 15:13
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
I mean PHPMyAdmin.

Field = dateplaced // [1] '$datenow'
Type = timestamp

I try insert number $datenow = time(); to second column, that i guest is a big number, but appears when i browse data as 0000-00-00 00:00:00 and NOT today's date , well ?
Reply With Quote
  #4 (permalink)  
Old 10-19-08, 15:32
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
this
Code:
$datenow = time();	 
	//  $datenow = date("H:i j/m/y", $tsnow);  // p.516-7
	$status="PENDING";
	$email6=$_SESSION['email'];
	$query = "INSERT INTO $BookingsTable VALUES(NULL,'$datenow',0,'$email6','$status','$datep','$dated','$Locationp','$Locationd','$days','$mostdaysrate','$vat','$off','$finalprice','$cat')";
looks like PHP to me. Im not aware you can run scripts like that in PHPMyAdmin
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 10-19-08, 21:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
the format for mysql is 'yyyy-mm-dd hh:mm:ss' -- no @
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 10-20-08, 00:46
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
Please note: I want to keep track date/time , placed the booking, pickup date(car rent) and, dropoff date...I set these all fields to timestamp ... to save a date in db/table how I must insert date in what format(a big number) ? or what ?
If I insert a big number to timestamp field this will show a date like
'yyyy-mm-dd hh:mm:ss'
in the table: "browse command" in phpmyadmin(mysql) ?
Reply With Quote
  #7 (permalink)  
Old 10-20-08, 00:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
please do a SHOW CREATE TABLE for your table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 10-20-08, 02:40
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
timestamp is a variant of datetime.. its set whenever the row is added or changed. so if you try to assign a value to a time stamp column you may have problems. if you have multiple timestamp columns they should all be set to the same value

use datetime datatype in place
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #9 (permalink)  
Old 10-22-08, 13:27
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
I try insert number $datenow = time(); to second column, that i guest is a big number, but appears when i browse data as 0000-00-00 00:00:00 and NOT today's date , well ?
0000-00-00 00:00:00 == A timestamp field to appear this what must be inserted ?

in my case I want to use time/date and compare it, appear only not expired bookings, sort by date etc ,... what to use ? what field type to use ?
Reply With Quote
  #10 (permalink)  
Old 10-22-08, 13:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
use DATETIME datatype

make sure you insert an actual datetime value, not a unix integer
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 10-25-08, 15:40
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
WHEN I take current time from
$datenow = time();
how insert in DATETIME datatype ?
Reply With Quote
  #12 (permalink)  
Old 10-25-08, 16:12
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
$DATENOW = format("Y-m-d H:i:s"); //FORMAT THE DATE IN MySQL form
$SQL = "Insert into mytable (my, column, list, mydatecolumn) values (my, values, list, $DATENOW);";
$sqlr=@mysql_query($SQL,$cnn) or die (echo ("myerrormessage".mysql_error());

$cnn is the variable containing a valid MySQL connection
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #13 (permalink)  
Old 10-25-08, 16:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
why generate the value in php and pass it to the database?

why not use the database function?

so instead of this --

$DATENOW = format("Y-m-d H:i:s"); //FORMAT THE DATE IN MySQL form
$SQL = "Insert into mytable (my, column, list, mydatecolumn) values (my, values, list, $DATENOW);";

you would run only this --

$SQL = "Insert into mytable (my, column, list, mydatecolumn) values (my, values, list, CURRENT_TIMESTAMP);";
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #14 (permalink)  
Old 10-26-08, 11:17
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
DB field type: timestamp, HOW IS BEING SAVED AND APPEARED ? SAVED AS BIG INT ?
Reply With Quote
  #15 (permalink)  
Old 10-26-08, 11:28
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
what does it matter how it is stored.. its a variant of a datetime column, one you cannot set yourself. think of it as a read only date time.

it gets changed every time there are changes applied to that row.

there are functions to manipulate that datatype both in MySQL and PHP.
http://bugs.mysql.com/bug.php?id=24895

it looks lke the datetime datatype is an 8 byte value, I'd expect it to be an integer being he number of clicks since an arbitary date (probably the Unix Epoch). you shouldn't be any direct mathmatical manipulation on any date time values, use the presupplied functions.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On