Update random dates - MySQL

Discussion in 'PHP' started by Success, Aug 11, 2009.

  1. #1
    I want to update the post_date of all the posts in a Wordpress to random dates within a range. For example, random dates between 2009-01-01 to current date.

    I tried this.

    UPDATE wp_posts SET post_date = '2008-01-01 08:00:00' + interval rand()*210 day + interval rand()*36000 second
    HTML:
    But the dates are all the same.

    I got the code from http://answers.yahoo.com/question/index?qid=20080430140007AARVfec

    Can any MySQL guru please advise?
     
    Success, Aug 11, 2009 IP
  2. Aces A

    Aces A Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I tried your code.

    UPDATE ft_cashier SET time = '2008-01-01 08:00:00' + interval rand()*210 day + interval rand()*36000 second

    SELECT transaction_id,time FROM ft_cashier

    
      	Edit   	Delete   	1  	2008-07-04 08:06:31
    	Edit 	Delete 	2 	2008-03-26 08:00:05
    	Edit 	Delete 	3 	2008-06-13 17:02:57
    	Edit 	Delete 	4 	2008-02-08 09:55:16
    	Edit 	Delete 	5 	2008-03-28 13:03:36
    	Edit 	Delete 	6 	2008-02-29 16:50:54
    	Edit 	Delete 	7 	2008-05-02 10:34:39
    	Edit 	Delete 	8 	2008-04-24 17:20:24
    	Edit 	Delete 	9 	2008-01-11 12:15:44
    	Edit 	Delete 	10 	2008-07-28 14:55:17
    
    Code (markup):
    Don't know why yours would work differently...
     
    Aces A, Aug 11, 2009 IP