Update DateTime

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Update DateTime

Post by AliasBDI »

I have a form with a hidden tag. I wanted it to grab the server time and put it in the value. Here is my hidden tag code:

Code: Select all

<input name="articles_date" type="hidden" id="articles_date" value="<?php echo datetime(); ?>">
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Try the date() function instead.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

I Got an Error

Post by AliasBDI »

I got an error of "Wrong parameter count for date()". I'm on a Windows Server if that helps. But the latest version of PHP is installed.

Here is my code:

Code: Select all

<?php echo date(); ?>
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Yeah you need to pass it the format for how you want the date:

Code: Select all

echo date("H:i d M Y");
etc. Check the manual page for more info on the format.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Okay

Post by AliasBDI »

I need in the MySQL datetime formatt. I think it is a set of 12 numbers. How would that look?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Use timestamp - time() - then convert on the other side to whatever format/type you wish.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

why don't you insert now() or NULL into the database instead of a variable generated by php?
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

here

Post by AliasBDI »

I tried now() but it did not work. here is my code:

Code: Select all

<?php
$updateSQL = sprintf("UPDATE con_articles SET title=%s, author=%s, img_th=IFNULL(%s,img_th), img=IFNULL(%s,img), teaser=%s, common=%s, topic_id=%s, content=%s, articles_date = now(), active=%s, search1=%s, search2=%s, search3=%s WHERE id=%s",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['author'], "text"),
                       GetSQLValueString($_POST['img_th'], "text"),
                       GetSQLValueString($_POST['img'], "text"),
                       GetSQLValueString($_POST['teaser'], "text"),
                       GetSQLValueString($_POST['common'], "text"),
                       GetSQLValueString($_POST['topic_id'], "text"),
                       GetSQLValueString($_POST['content'], "text"),
                       GetSQLValueString($_POST['articles_date'], "date"),
                       GetSQLValueString(isset($_POST['active']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['search1'], "text"),
                       GetSQLValueString($_POST['search2'], "text"),
                       GetSQLValueString($_POST['search3'], "text"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_econtrol_truth411com, $econtrol_truth411com);
?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

varchar (and the like types) values have to be between quotes, thus:

Code: Select all

foo='bar'


instead of the foo=bar you are doing now.
cookie
Forum Newbie
Posts: 3
Joined: Wed Dec 08, 2004 5:06 am

Post by cookie »

patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

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

Change line 2 to:

Code: Select all

$updateSQL = sprintf("UPDATE con_articles SET title=%s, author=%s, img_th=IFNULL(%s,img_th), img=IFNULL(%s,img), teaser=%s, common=%s, topic_id=%s, content=%s, articles_date=%s, active=%s, search1=%s, search2=%s, search3=%s WHERE id=%s",

Change line 11 to:
GetSQLValueString(isset($_POST['articles_date']) ? "true" : "", "defined","NOW()","0"),
:) :)
patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

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