:o
[php]for ($i = 00; $i <= 31; $i++){
print “<option value=”$i">$i\n"; }[/php]
These use logical increments taking away the null of 0 in 01… but I am doing this for a date to database and need the 0 for YYYYmmdddd.
any help guys?
:o
[php]for ($i = 00; $i <= 31; $i++){
print “<option value=”$i">$i\n"; }[/php]
These use logical increments taking away the null of 0 in 01… but I am doing this for a date to database and need the 0 for YYYYmmdddd.
any help guys?
Hello bushkid85, Do not worry, Just use below code it will resolve your problem [php] <? function srlogic($n) { return printf("%02x\n", $n); } for ($i = 0; $i <= 31; $i++) { if($i < 10) { $nox = explode(' 3',srlogic($i)); $no = $nox[1]; } else $no = $i; print "$no\n"; } ?> [/php] I hope this will helpful for you. Reply your feedback. ~~SR~~
Thank pal, but that funtion just left me with blank spaces until the number 10-31.
Hey kid,
For an INT, there is no such thing as “00”. Any 01 09 099 will turn into 1 9 99, etc.
You can use the number format function to create whatever you need to get around this.
You mentioned dates in your note. I use this format for a nice timestamp. I usually create an additional field in my database (usually in every table) and make the last field “TimeStamp” as a string. Then, I use this format to fill it: date(‘Y-m-d H:i:s’) This gives a nice and unique timestamp. I use it whenever a row in a table is updated or created. It gives me a very nice time record of “Last-Updated” for everything I put into the database. Works very nice. A query to insert something from a form would be something like this:
$query = “INSERT INTO MyTable (Name, Heading, Content, LastUpdated) VALUES (’” . $_POST[‘Name’] . “’, '” . $_POST[‘Heading’] . “’, '” . $_POST[‘Content’] . "’, ". date(‘Y-m-d H:i:s’) . “’) WHERE Name = '” . $_POST[‘Name’] . “’”;
You can change the form of your Date anyway you want or need. Have a look at this link. It explains all format options as there are tons! http://php.net/manual/en/function.date.php
*** Lastly Note: The time used in PHP is the “local” time, therefore it is based out of the server wherever it is located. So, either pull the local time from the browser and send it to the server if needed tiem-where-user-is.
Hope that helps…
Hello bushkid85, My last function is only used when $i is less than 10 and when $i is greater than 9 there is no need to call that function. But if you have not getting my point than it's ok, Do not worry here i am going to provide another solution. use below code[php]
<? # below code for($i=0;$i<=31;$i++) { if($i < 10) { $no ="0".$i; } else { $no = $i; } print "$no\n"; } ?>[/php]
I hope this will resolve your issue.
Reply Your Feedback
SR
Cheers pal, I like the use of timestamp there. Im just looking for easy (lazy) solutions.
I have sorted it now, dates with databases are so annoying haha, I am 95% there with them now.
Thank you Sarthak Patel - all helpful.