joesaddigh Posted October 19, 2011 Share Posted October 19, 2011 Hi, When I do this the result is a date of zeros? $DateAndTime = date('d-m-y', strtotime($DateAndTime)); All I want is a date in format of DD0MM-YYY and the Time in HH:MM::SS Any help would be great! I know it is basic, Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/ Share on other sites More sharing options...
Zane Posted October 19, 2011 Share Posted October 19, 2011 When I do this the result is a date of zeros? What is inside the variable $DateAndTime? Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/#findComment-1280639 Share on other sites More sharing options...
joesaddigh Posted October 19, 2011 Author Share Posted October 19, 2011 Nothing its declared and assigned in the same statement $DateAndTime = date('d-m-y', strtotime($DateAndTime)); All I want is the current date in the format DD-MM-YYYY followed by the time. This must be a simple task? Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/#findComment-1280641 Share on other sites More sharing options...
Pikachu2000 Posted October 19, 2011 Share Posted October 19, 2011 Yes it is simple, but look at what you're doing. You can't use the value of $DateAndTime like that. You're trying to assign the result to it based on it's value, which doesn't yet exist. Are you just trying to assign the current time to it? Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/#findComment-1280645 Share on other sites More sharing options...
Zane Posted October 19, 2011 Share Posted October 19, 2011 Yes it is simple, but look at what you're doing. You can't use the value of $DateAndTime like that. You're trying to assign the result to it based on it's value, which doesn't yet exist. Are you just trying to assign the current time to it? QFT just change it to this if you want the current time. $DateAndTime = date('d-m-y', time()); strtotime is meant to do exactly what the function suggests.. turn a string into a timestamp. An example string being. $variable = strtotime("4 days ago"); Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/#findComment-1280654 Share on other sites More sharing options...
joesaddigh Posted October 20, 2011 Author Share Posted October 20, 2011 I had the code like that at some point. the output of that was this: 2020-10-11 00:00:00?? What am I doing wrong? Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/#findComment-1280743 Share on other sites More sharing options...
joesaddigh Posted October 20, 2011 Author Share Posted October 20, 2011 hi, It was the DB field being stored as a Date. Changed to a string so will have a play now. Getting better results. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/#findComment-1280749 Share on other sites More sharing options...
Drummin Posted October 20, 2011 Share Posted October 20, 2011 Capital Y. $DateAndTime=date('d-m-Y H:i:s'); Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/#findComment-1280754 Share on other sites More sharing options...
joesaddigh Posted October 20, 2011 Author Share Posted October 20, 2011 Perfect thanks for your help. It was the DB that was messing it all up for me. The code posted now works perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/249418-formatting-date/#findComment-1280876 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.