Ryoku Posted August 9, 2008 Share Posted August 9, 2008 I had a book that covered this but its packed up and buried under a mountain of boxes. I'm having some problems messing around with dates. when i try to do something basic to the values PHP returns i lose my leading zero(s). how do you force/require a string to be a certain length? Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/ Share on other sites More sharing options...
php_b34st Posted August 9, 2008 Share Posted August 9, 2008 try something like this: $d = 5; $c = sprintf('%03d',$d); echo $c; Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612520 Share on other sites More sharing options...
cooldude832 Posted August 9, 2008 Share Posted August 9, 2008 don't use sprintf php.net/date will show u all the parameters to return various date items. Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612521 Share on other sites More sharing options...
Ryoku Posted August 9, 2008 Author Share Posted August 9, 2008 don't use sprintf php.net/date will show u all the parameters to return various date items. I actualy started on the php.net manual but its didn't help me with the problem of losing my formatting when i printed the results. after i would explode() the date into an array to work with the numbers once i used any math on the values they lost their formatting. if I'm going to transpose the base date into another value i need to know how to force the length of the string. Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612577 Share on other sites More sharing options...
cooldude832 Posted August 9, 2008 Share Posted August 9, 2008 transpose date? mktime() strtotime() very strong functions and save you time the date library in php is very strong and you shouldn't ever have to manipulate dates outside of it. Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612586 Share on other sites More sharing options...
Barand Posted August 9, 2008 Share Posted August 9, 2008 try using strtotime on a date in dd/mm/yyyy format then. Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612592 Share on other sites More sharing options...
Ryoku Posted August 9, 2008 Author Share Posted August 9, 2008 well this is the situation I'm in. I'm messing with functions I'd like to add to, my first, news script. I either have the date provided by PHP from the date() or i have the date retrieved from the entries in my DB server. I'd like the ability to post/pre-date news (to be posted) by adding or subtracting from the int date and still have it compatible with the date format of the DB server where it will end up. but when i attempt to script for pre/post any math i do to the value returns a value of a single digit not 2 digits as the DB formatting requires (to my knowledge) i get 9 where i need 09 [since i did these tests today (08/09/08)] Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612596 Share on other sites More sharing options...
Barand Posted August 9, 2008 Share Posted August 9, 2008 Perhaps if you were to post some code, and show us the formats you are trying to convert to and from, then we could be of more help. Telling us you once had a book doesn't gve us much information. Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612604 Share on other sites More sharing options...
Ryoku Posted August 9, 2008 Author Share Posted August 9, 2008 well i think i figured out a way, using mkdate() to reformat the date, if i have an idate('Y') to just call the values and manipulate them that way i throw the values back into a date('Y-m-d',mktime(0,0,0,$curmonth,$curdate,$curyear)) i get the result I'm looking for... ^solved although it still really dosen't answer my question of how to force a string length, how ever mute, =P i remember a tiny piece of the over all code to pull it off it looked something like this [/./.\\/] but that's all i remember and i have no idea what that example means... Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612611 Share on other sites More sharing options...
Jabop Posted August 9, 2008 Share Posted August 9, 2008 http://www.php.net/strpad Link to comment https://forums.phpfreaks.com/topic/118954-solved-i-had-a-book-once/#findComment-612615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.