[SOLVED] date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

date

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post the code
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post 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

?>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

Thank you. I'll try that and let you know
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post 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
Last edited by ddragas on Tue Jul 13, 2004 2:03 am, edited 2 times in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post 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
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

Figured out. My mistake :oops:

Thank you all
Post Reply