Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php problems with dates
Old 09-09-2010, 05:27 PM php problems with dates
Junior Talker

Posts: 1
Name: Sam Marcotte
Trades: 0
I am trying updates some dates in my system from mm/dd/yyyy to dd mmm yyyy but my script is not working - I am currently ad

update tng_events set deathdatetr = replace(date("yyyy-mm-dd",deathdate))
and set deathdate = replace(date("dd-mmm-yyyy",deathdatetr))
limit 0,2;

Any help would be great

Thanks Sam
samiam48 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-11-2010, 02:36 AM Re: php problems with dates
Experienced Talker

Posts: 40
Name: Fernades jacob
Trades: 0
I am not sure about it.this might work.try this

UPDATE tng_events SET `deathdatetr` = replace(`deathdatetr`, "mm/dd/yyyy", "dd/mmm/yyyy")

Last edited by fernades; 09-11-2010 at 02:37 AM..
fernades is offline
Reply With Quote
View Public Profile
 
Old 09-11-2010, 05:21 PM Re: php problems with dates
mad_willsy's Avatar
Super Spam Talker

Latest Blog Post:
R&R Catering Hire Testimonial
Posts: 805
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
Trades: 0
Welcome to WT samiam48,

Try (wrote on the fly and i know nothing about your database structure):
PHP Code:
<?php
//connect to database (see php.net/mysql_connect)
//select database (see php.net/mysql_select_db)
$query mysql_query("SELECT id,deathdate FROM tng_events");
while(
$array mysql_fetch_array($query)){
mysql_query("UPDATE tng_events SET deathdate ='".
date("d/m/Y"strtotime($array[1]))."' WHERE id = '".$array[0]."' LIMIT 1");
}
?>
__________________
Wont :P

Please login or register to view this content. Registration is FREE

Last edited by mad_willsy; 09-11-2010 at 05:26 PM.. Reason: Mistake in code
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
Old 09-18-2010, 09:06 PM Re: php problems with dates
Novice Talker

Posts: 5
Name: Marcel Dijkgraaf
Location: Holland
Trades: 0
yeah, it's better to make an extra column int the table and handle the conversion in PHP, after each conversion you could do an SQL UPDATE... a lot of them
oortm is offline
Reply With Quote
View Public Profile
 
Old 09-18-2010, 09:16 PM Re: php problems with dates
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
What is the data type of deathdatetr?

It should be a TIMESTAMP or DATETIME, in which case the format in the DB doesn't matter, the datatype will have the date and time innately as a part of the object.

You should retrieve the value into a new DateTime() object, and use DateTime::format() to change the display format.
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-18-2010, 10:30 PM Re: php problems with dates
dreamconception's Avatar
Average Talker

Posts: 26
Name: Dan
Trades: 0
Yes, a unix timestamp is definitely much better or just datetime. But now that the database scheme already is created then I agree with jasonliu, do this in PHP. You will have much better control. mad_willsy already showed how you can do it.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
dreamconception is offline
Reply With Quote
View Public Profile Visit dreamconception's homepage!
 
Reply     « Reply to php problems with dates
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23984 seconds with 12 queries