Page 1 of 1

date

Posted: Mon Jul 12, 2004 3:46 am
by ddragas
Hi all

I've got question about dates.

I've inserted in db in column "date" witch type is date,
in Sql query "now()"

Every time I take out information from that column it shows me todays date, and not date I've inserted.

Why

Posted: Mon Jul 12, 2004 3:53 am
by feyd
post the code

Posted: Mon Jul 12, 2004 6:58 am
by ddragas

Code: Select all

<?php

include("con_db.php");

$query = "INSERT INTO  apartmani (
Sifra_apartmana,
iznajmljivac,
Naziv_objekta,
adresa,
mjesto,
postanski_broj,
city,
zupanija,
datum_objave,
broj_osoba)

VALUES

 ('$Sifra_apartmana',
 '$broj',
 '$Naziv_objekta',
 '$address', 
 '$mjesto',
 '$postanski_broj', 
 '$city', 
 '$zupanija', 
now(),
'$kapacitet_osoba_smjeĊĦtaja' )";


mysql_query($query) or die (mysql_error());


<?php

?>

Posted: Mon Jul 12, 2004 8:30 am
by malcolmboston
why not just use

Code: Select all

$unformatted_time = time();
then insert it into the database in place of now()
(i recommend changing field type to 12 int)

This makes it much much easier to later format as you can do something like the following

Code: Select all

$formatted_time = date("D M j G:i:s T Y", $unformatted_time);
believe me, it makes it much easier in the long run

Posted: Mon Jul 12, 2004 8:53 am
by ddragas
Thank you. I'll try that and let you know

Posted: Mon Jul 12, 2004 2:56 pm
by ddragas
Hi malcolmboston

I've changed code like you sugested me, and it works fine. As always it has to be some "but" :wink:

I've got 4 columns - same formated int (12) for dates

1. Date of advertisment
2. Date of modification
3. Date of paying
4. Expiry date

For inserting in db I use like you sugested me

Code: Select all

$date_of_creation = time();
insert into table (date_of_creation) values ('$date_of_creation')


For modification

Code: Select all

$date_of_modification = time(); 

UPDATE table SET
date_of_modification = '$date_of_modification'


and when I want to see those values I use

Code: Select all

$date_of_creation=$row["date_of_creation"];
$date_of_modification=$row["date_of_modification"];


if(isset($date_of_creation)){
$ispis_datuma_objave = date("d.m.Y G:i:s ", $date_of_creation); 
echo "Date of creation: " . $ispis_datuma_objave . "<br>\n"; }

if(isset($date_of_modification)){
$ispis_datuma_izmjene = date("d.m.Y G:i:s ", $date_of_modification); 
echo "Date of last change: " . $ispis_datuma_izmjene  . "<br>\n";}

Now. first when I create record, in date of advertisment is inserted value that should be inserted, and that can be seen when I want to change my record.

After I change my record, new value is inserted in date of modification, and in date of advertisment.

In date of modification is inserted value that should be inserted, and in date of advertisment is updated just a year 2004 eaven if I did not mention column date of advertisment in UPDATE query.

I find it very strange. If you or somebody else could help me or give me right direction in advice.

Regards


feyd | LAST WARNING, use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php

Posted: Mon Jul 12, 2004 5:16 pm
by pickle
I'd love to help, you've written your problem out nice and clearly, except for this paragraph...
ddragas wrote: In date of modification is inserted value that should be inserted, and in date of advertisment is updated just a year 2004 eaven if I did not mention column date of advertisment in UPDATE query.
Could you explain this again? It's a little hard to understand. Thanks.

Posted: Tue Jul 13, 2004 1:48 am
by ddragas
After UPDATE query, in column date_of_modification inserted value is what should be inserted, and column date_of_advertisment is updated with value 2004 like year 2004, eaven if I did not mention column date_of_advertisment in UPDATE query.

hope this can help, if it doesn't help please let me know.

Regards

Posted: Tue Jul 13, 2004 6:19 am
by ddragas
Figured out. My mistake :oops:

Thank you all