[SOLVED] date
Moderator: General Moderators
date
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
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
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
?>-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
why not just use
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
believe me, it makes it much easier in the long run
Code: Select all
$unformatted_time = time();(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);Hi malcolmboston
I've changed code like you sugested me, and it works fine. As always it has to be some "but"
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
insert into table (date_of_creation) values ('$date_of_creation')
For modification
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
I've changed code like you sugested me, and it works fine. As always it has to be some "but"
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();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 useCode: 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
Last edited by ddragas on Tue Jul 13, 2004 2:03 am, edited 2 times in total.
I'd love to help, you've written your problem out nice and clearly, except for this paragraph...
Could you explain this again? It's a little hard to understand. Thanks.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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
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
hope this can help, if it doesn't help please let me know.
Regards