Jump to content

Convert DD/MM/YYYY to YYYY/MM/DD ?


mikemeadeuk

Recommended Posts

Hi Guys,

 

I need a way of converting DD/MM/YYYY to YYYY/MM/DD via one php line. any ideas how I would accomplish this?

 

Basically, I have a bit of kit that allows me to change CSV data before it imports into my application. However I seem to only be able to use standard PHP functions and not custom functions.

 

Any ideas would be much appreciated.

 

cheers,

 

mike

 

 

Link to comment
Share on other sites

Hi Guys,

 

thanks for the replys. I am limited to what I can do, as I can only enter the php code into a text box. This is the instructions I have:

 

------

Advanced expressions use php eval() function, it can be also very powerful, example:

{{substr("{item.expiry_date}",0,4}}

------

 

 

Do you know if there is a way to convert the date into the format I need using eval()? If you wondering, {item.expiry_date} refers to the column expiry_date in my CSV file.

 

Please excuse my limited knowledge.

 

thanks

 

mike

 

 

Link to comment
Share on other sites

hi, it works fine in in a standalone php file yes. However I am using magento with this:  http://sourceforge.net/apps/mediawiki/magmi/index.php?title=Value_Replacer

 

And this application uses eval() to allow php functions to alter the CSV file before importing to my magento website.

 

This is what I did, using Barands code, and I placed it within double curly braces as the application advises. And {item.StartDate} refers to StartDate in my CSV file.

 

{{list ($d, $m, $y, $h, $i, $s) = sscanf({item.StartDate}, '%d/%d/%d %d:%d:%d');$ymd = date('Y-m-d H-i:s', mktime($h,$i,$s,$m,$d,$y)) ;}}

 

Any ideas what Im doing wrong?

 

Thanks

 

Mike

Link to comment
Share on other sites

sorry, this even:

 

{{list ($d, $m, $y, $h, $i, $s) = sscanf({item.StartDate}, '%d/%d/%d %d:%d:%d');{item.StartDate} = date('Y-m-d H-i:s', mktime($h,$i,$s,$m,$d,$y)) ;}}

 

This works perfectly well in a single php file, but if I put it within eval() it highlights as an error, I'm not overly clued up as you can tell, so hopefully someone can point me in the right direction.

 

thanks

Link to comment
Share on other sites

*Readies the tar, feathers, torches and pitchforks.* Bad, Barand, bad! Now you'll have to be punished.

 

mikemeadeuk: I'd advice you to edit the actual code in question, instead of trying to write pseudo-code for a third party wrapper with (apparently) lacking documentation. Reduce the complexity when it is not needed, and you'll find that a whole lot of headaches will simply vanish.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.