ghurty Posted January 26, 2010 Share Posted January 26, 2010 I am having troubles convert a two variables into a date format: $OMONTH = "08"; $ODAY = 26; $DATELONG = DATE("M d", strtotime("{$OMONTH} {ODAY}")); echo $DATELONG . " Long DAte"; It should say Jan 26, but instead it is displaying DEC 31. Preferably, I would want it to print out "Tuesday January 26". Thanks Quote Link to comment https://forums.phpfreaks.com/topic/189799-problem-using-strtotime-to-convert-two-variables-into-a-date/ Share on other sites More sharing options...
premiso Posted January 26, 2010 Share Posted January 26, 2010 Do you mean: {ODAY} to be {$ODAY} ? Quote Link to comment https://forums.phpfreaks.com/topic/189799-problem-using-strtotime-to-convert-two-variables-into-a-date/#findComment-1001607 Share on other sites More sharing options...
pernest Posted January 26, 2010 Share Posted January 26, 2010 I think that the problem is more than the missing dollar sign! strtotime expects a string like $todays_date = "03-07-1993"; Its defaults to Dec 31 or Jan 01 if it doesn't understand your date format, for example echo DATE("M d", strtotime("Bunch of arse")); is jan 01 From what I can gather you have to include a year. And its the capital 'l' (a lower-case L) which gives you the day of the week, ie echo DATE("L M d", strtotime("17-6-1963")); Quote Link to comment https://forums.phpfreaks.com/topic/189799-problem-using-strtotime-to-convert-two-variables-into-a-date/#findComment-1001612 Share on other sites More sharing options...
ghurty Posted January 26, 2010 Author Share Posted January 26, 2010 Thank you. What would the best way for me to take a date (ex: 012510) and convert it into three sepereate variables: $month, $day, $dayoftheweek. So the for the given example, Month will = Janurary Day will = 25 Day of week will = Monday. I would need it as three seperate variables. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/189799-problem-using-strtotime-to-convert-two-variables-into-a-date/#findComment-1001623 Share on other sites More sharing options...
salathe Posted January 26, 2010 Share Posted January 26, 2010 The two lines below extract the day, month and year from your example date using sscanf and gets the day of the week using those values and strtotime/date. It's just one example of getting what you wanted. sscanf('012510', '%02d%02d%02d', $day, $month, $year); $dayoftheweek = date('l', strtotime("20$year-$month-$day")); var_dump($month, $day, $dayoftheweek); Quote Link to comment https://forums.phpfreaks.com/topic/189799-problem-using-strtotime-to-convert-two-variables-into-a-date/#findComment-1001751 Share on other sites More sharing options...
ghurty Posted January 26, 2010 Author Share Posted January 26, 2010 I just tried that, but for some reason, no matter what, it is outputting Wednesday. The month and day are working, but not the day of the week. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/189799-problem-using-strtotime-to-convert-two-variables-into-a-date/#findComment-1001960 Share on other sites More sharing options...
salathe Posted January 26, 2010 Share Posted January 26, 2010 In the first line, the $month and $day variables are in the wrong places (switch them around) since obviously there is no month 25! (Sorry) This was a very simple mis-type and something you really should have been able to figure out yourself, considering you knew the input given was in ddmmyy format. As for it "no matter what" outputting Wednesday, I've no idea how you got it to do that. Quote Link to comment https://forums.phpfreaks.com/topic/189799-problem-using-strtotime-to-convert-two-variables-into-a-date/#findComment-1002018 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.