2

我在查询字符串中有一个生日,例如:

?birthdate=1991-01-01

我的代码如下:

$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);
if (!$customer->getId()) {
    $customer->setEmail($email);
    $customer->setFirstname($name);
    $customer->setLastname($lastname);
    $customer->setPassword($password);
    $customer->setGender(
    Mage::getResourceModel('customer/customer')
        ->getAttribute('gender')
        ->getSource()
        ->getOptionId($gender)
    );
}

就像我想要的一样:

$customer->setBirthday($date);

任何解决方案?

4

2 回答 2

4

生日字段实际上被称为dob。尝试:

$customer->setDob('1991-01-01');

或添加以下日期代码:

list($y, $m, $d) = explode('-', $birthday);

$date=date('m/j/Y', strtotime("$y-$m-$d"));

$customer->setDob($date);
于 2013-02-27T23:10:22.783 回答
0

谢谢马特。我修改了您的解决方案(因为我也遇到了 01-01-1970 日期的问题)。也许有人可以使用它:

        // $birthday format m/d/y -> convert to m-d-Y
        $datetime = DateTime::createFromFormat('m/d/y', $birthday);
        $customer->setDob($datetime->format('m-d-Y'));
        $customer->save();
于 2016-03-15T16:30:59.480 回答