bajangerry Posted August 12, 2009 Share Posted August 12, 2009 Guys, I am trying to create a date string of dd/mm/yyyy from a table that has the dd, mm and yyyy info in different columns. My problem is how to get the / in the string without getting errors. So far I have the data query working fine, that is not the problem and I can echo as follows: echo ($row->day); echo ($row->month); echo ($row->year); and get for example 12082009 so the data access side of things is fine. Now, how do I get this data into a string that, if echoed, will give me 12/08/2009 instead? I need to use this string to test against another table that has the date in the format of dd/mm/yyyy in a single column. Looking forward to your responses Quote Link to comment https://forums.phpfreaks.com/topic/169943-create-a-date-string-ddmmyyy-from-table-with-dd-mm-and-yyyy-separated/ Share on other sites More sharing options...
irvieto Posted August 12, 2009 Share Posted August 12, 2009 Hi Use mysql CONCAT() function to retrieve the data already formated. You should really fix table in order to have only 1 column of type date and remove the other 3 columns. In php the dot character is the concatenation symbol. example: echo 'Foo'.'-'.'bar'; //prints "Foo-bar" Quote Link to comment https://forums.phpfreaks.com/topic/169943-create-a-date-string-ddmmyyy-from-table-with-dd-mm-and-yyyy-separated/#findComment-896540 Share on other sites More sharing options...
fabimc Posted August 12, 2009 Share Posted August 12, 2009 try: SELECT CONCAT_WS('/','day','month','year') as date; Quote Link to comment https://forums.phpfreaks.com/topic/169943-create-a-date-string-ddmmyyy-from-table-with-dd-mm-and-yyyy-separated/#findComment-896552 Share on other sites More sharing options...
Daniel0 Posted August 12, 2009 Share Posted August 12, 2009 You should store dates in a DATE field type. Quote Link to comment https://forums.phpfreaks.com/topic/169943-create-a-date-string-ddmmyyy-from-table-with-dd-mm-and-yyyy-separated/#findComment-896555 Share on other sites More sharing options...
bajangerry Posted August 12, 2009 Author Share Posted August 12, 2009 Ok, I know this data is not stored "correctly" but this is the way it is, not by choice on my part, this is how I found it. I will try the CONCAT() function. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/169943-create-a-date-string-ddmmyyy-from-table-with-dd-mm-and-yyyy-separated/#findComment-896565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.