Dragosvr92 Posted January 4, 2012 Share Posted January 4, 2012 Hello, i need a fast convertor that converts the date format 03-03-2008, 08:26 PM into a timestamp fast. Like, you paste 03-03-2008, 08:26 PM into a post form, submit and it gives you the time stamp. I made a convertor a whille ago, but you need to insert each numbers into a separate input box (day, months, year etc) I cant remember how exactly it functions etc asi haventtouched PHP In a while..... Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/ Share on other sites More sharing options...
Pikachu2000 Posted January 4, 2012 Share Posted January 4, 2012 You mean a Unix timestamp? strtotime Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1304290 Share on other sites More sharing options...
Dragosvr92 Posted January 4, 2012 Author Share Posted January 4, 2012 You mean a Unix timestamp? strtotime Yes. Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1304294 Share on other sites More sharing options...
Dragosvr92 Posted January 9, 2012 Author Share Posted January 9, 2012 Well that was very helpful.. Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1305751 Share on other sites More sharing options...
ManiacDan Posted January 9, 2012 Share Posted January 9, 2012 strtotime() won't work well on this particular format because it's ambiguous. You should use explode() to pull the date apart and then use mktime() Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1305762 Share on other sites More sharing options...
Dragosvr92 Posted January 9, 2012 Author Share Posted January 9, 2012 strtotime() won't work well on this particular format because it's ambiguous. You should use explode() to pull the date apart and then use mktime() Thank you, i will look at that tomorrow. I didnt thought on using explode() I remembered why i had to use a input for each area and didnt made it like this Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1305905 Share on other sites More sharing options...
Dragosvr92 Posted January 9, 2012 Author Share Posted January 9, 2012 It took me a few hours to figure it out, and make it, after i last posted,but i have done it using preg_split() as i needed to split it by the 3 symbols => - , : Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1305962 Share on other sites More sharing options...
ManiacDan Posted January 10, 2012 Share Posted January 10, 2012 $a = '03-03-2008, 08:26 PM'; list($date, $time) = explode(', ', $a); list($month, $day, $year) = explode('-', $date); $b = strtotime("{$year}-{$month}-{$day} {$time}"); echo date('c', $b); //2008-03-03T20:26:00-05:00 -Dan Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1305971 Share on other sites More sharing options...
Dragosvr92 Posted January 11, 2012 Author Share Posted January 11, 2012 Thanks Dan, but that doesnt look like what i need. I Made the script myself, but i have a problem on detecting if its either morning or night, using mktime(). For example there may be 03-05-2008, 02:17 AM, and 03-05-2008, 02:17 PM. A solution i thought about would be to make some if statement and check if PM is selected, and if it is, check an array and if it finds, for example: " 03 " it replaces it with " 15 ". here is some lame script i made..... $chars[5] outputs PM/AM $chars[3] outputs the hour <?//AM if ($chars[5]=='AM' || $chars[3]) { array{ "01" = "13"; "02" = "14"; "03" = "15"; "04" = "16"; "05" = "17"; "06" = "18"; "07" = "19"; "08" = "20"; "09" = "21"; "10" = "22"; "11" = "23"; "12" = "00"; } } ?> Can you please give me a example? Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1306306 Share on other sites More sharing options...
ManiacDan Posted January 11, 2012 Share Posted January 11, 2012 Exactly what I posted above, except replace 'c' with 'A' Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1306320 Share on other sites More sharing options...
Dragosvr92 Posted January 11, 2012 Author Share Posted January 11, 2012 With c it outputs 2008-03-03T20:26:00+00:00 With A it outputs PM/AM This is my Code: <? if (isset($_POST['DATE'])) { $str = $_POST['DATE']; $chars = preg_split('/[-:, ]+/', $str); $timestamp = mktime($chars[3], $chars[4], '00', $chars[0], $chars[1], $chars[2]); echo date('m-d-Y, h:i A', $timestamp); echo '<br />', '<br />'; echo $timestamp; } ?> I just need to make an array and replace for example 08 with 20, so that the time may be set as PM. I think you are getting confused :-\ Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1306328 Share on other sites More sharing options...
ManiacDan Posted January 11, 2012 Share Posted January 11, 2012 Ok, really, date() can output a date in any format you want. Check the manual page. Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1306469 Share on other sites More sharing options...
Dragosvr92 Posted January 11, 2012 Author Share Posted January 11, 2012 And i need to output the date using mktime() to output the timestamp. the timestamp is what i need, not the date. Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1306476 Share on other sites More sharing options...
ManiacDan Posted January 11, 2012 Share Posted January 11, 2012 $b in my example is already a timestamp. Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1306535 Share on other sites More sharing options...
Dragosvr92 Posted February 20, 2012 Author Share Posted February 20, 2012 Thank You very much Dan. Sorry for my late reply. Link to comment https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/#findComment-1319086 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.