HostGator Hosting
 
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Web Directory

Go Back   Webmaster Forum > Designing and Developing Websites > Programming > PHP / MySQL

PHP / MySQL Discussions and help on PHP and MySQL.

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-08-2007, 06:29 AM
technoguy technoguy is offline
WMG Citizen
 
Join Date: Mar 2007
Posts: 436
iTrader: (0)
technoguy is on a distinguished road
Default Flipping date in php

I have seen that many people are searchign for date formatting for dd-mm-yyyy format while mysql default supports yyyy-mm-dd , here is a function which flip the date. I hope you will find it useful

<?php
function flipdate($dt, $seperator_in = '-', $seperator_out = '-')
{
return implode($seperator_out, array_reverse(explode($seperator_in, $dt)));
}
?>
Reply With Quote
Sponsored Links
Register and sign in to hide this ad block

  #2 (permalink)  
Old 03-08-2007, 06:59 AM
alphaRomeo alphaRomeo is offline
WMG Resident Alien
 
Join Date: Mar 2007
Posts: 242
iTrader: (1)
alphaRomeo is on a distinguished road
Default

I wonder what the use of that would be.
PHP already has a built-in date function that you can use to format dates.
Reply With Quote
  #3 (permalink)  
Old 03-08-2007, 07:03 AM
technoguy technoguy is offline
WMG Citizen
 
Join Date: Mar 2007
Posts: 436
iTrader: (0)
technoguy is on a distinguished road
Default

Yes , php is giving you facility to having date format. But its diffcult to set for date other than current date. Plus no need to format it for every instance at our function call.
Reply With Quote
  #4 (permalink)  
Old 03-19-2007, 11:20 AM
blokey blokey is offline
WMG Resident Alien
 
Join Date: Mar 2007
Posts: 93
iTrader: (0)
blokey is on a distinguished road
Default

Difficult to set for a date other than the current? Not exactly. A better method:

$new_date = strftime('%d-%m-%Y', strtotime($old_date));

The advantage is that strtotime() will convert a timestamp in a wide range of formats.
Reply With Quote
  #5 (permalink)  
Old 03-19-2007, 01:05 PM
technoguy technoguy is offline
WMG Citizen
 
Join Date: Mar 2007
Posts: 436
iTrader: (0)
technoguy is on a distinguished road
Default

Great! Someone says "Everything is easy if you know it" , Now I know this technique so I can say its not tought. I would prefer to use this format now.

Thanks for your help.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT. The time now is 05:58 AM.



Freelance Web Designers
Work At Home Forum
Ad Marketplace
Online Deals and Bargains
Ad Marketplace and Auctions Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0