<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1012538" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1012538</link>
    <description></description>
    <language>en</language>
          <item>
    <title>sprintf(), Time::Local and Date::Calc</title>
    <link>https://www.webmaster-forums.net/serverside-scripting/date-function#comment-1072921</link>
    <description> &lt;p&gt;If you want to do simple string formatting, use the sprintf() and printf() functions (borrowed from C, of course):&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;($day,$mon,$year) = (3,4,1982);&lt;br /&gt;$date = sprintf &amp;quot;%02d/%02d/%4d&amp;quot;, $mon, $day, $year;&lt;br /&gt;print $date;&amp;nbsp; # 04/03/1982&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Read &lt;strong&gt;perldoc -f sprintf&lt;/strong&gt; and &lt;strong&gt;perldoc -f printf&lt;/strong&gt; for information on those functions.&lt;/p&gt;
&lt;p&gt;For date calculations, you &lt;em&gt;should&lt;/em&gt; be safe in using the Time::Local module (it comes with Perl):&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;use Time::Local;&lt;br /&gt;$now = &amp;#039;10/17/2000&amp;#039;;&lt;br /&gt;$plus_days = 500;&lt;br /&gt;$future = add_days($now,$plus_days);&lt;br /&gt; &lt;br /&gt;sub add_days {&lt;br /&gt;&amp;nbsp; my ($date,$days) = @_;&lt;br /&gt;&amp;nbsp; my ($m,$d,$y) = split &amp;#039;/&amp;#039;, $date;&lt;br /&gt;&amp;nbsp; my $time;&lt;br /&gt; &lt;br /&gt;&amp;nbsp; $m--, $y -= 1900;&amp;nbsp; # $m is 9, $y is 100&lt;br /&gt;&amp;nbsp; $time = timelocal(0,0,0,$d,$m,$y);&lt;br /&gt;&amp;nbsp; $time += 86400 * $days;&lt;br /&gt;&amp;nbsp; ($d,$m,$y) = (localtime($time))[3,4,5];&lt;br /&gt;&amp;nbsp; return sprintf &amp;quot;%02d/%02d/%4d&amp;quot;, $m+1, $d, $y+1900;&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;If you&#039;re doing more complex date computation, I highly suggest looking into the Date::Calc module, available on CPAN.&lt;/p&gt;
&lt;p&gt;[Edited by japhy on 10-17-2000 at 05:21 PM]&lt;/p&gt;
 </description>
     <pubDate>Tue, 17 Oct 2000 21:19:15 +0000</pubDate>
 <dc:creator>japhy</dc:creator>
 <guid isPermaLink="false">comment 1072921 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/date-function#comment-1072465</link>
    <description> &lt;p&gt;Thanks all,&lt;/p&gt;
&lt;p&gt;I had:&lt;/p&gt;
&lt;p&gt;if($day &amp;lt; 10) {$day = &quot;0$day&quot;;}&lt;br /&gt;
if($month &amp;lt; 10) {$day = &quot;0$month&quot;;}&lt;/p&gt;
&lt;p&gt;So I think we&#039;re all in the same ball park!&lt;/p&gt;
&lt;p&gt;Denise &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Oct 2000 18:22:54 +0000</pubDate>
 <dc:creator>Denise</dc:creator>
 <guid isPermaLink="false">comment 1072465 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/date-function#comment-1072464</link>
    <description> &lt;p&gt;I don&#039;t know of a &#039;proper&#039; way to do it.  But this would work:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;$num=&amp;quot;0$num&amp;quot;,if(length($v)==1);&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Oct 2000 16:29:22 +0000</pubDate>
 <dc:creator>Rob Pengelly</dc:creator>
 <guid isPermaLink="false">comment 1072464 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/date-function#comment-1072462</link>
    <description> &lt;p&gt;Hi Denise,&lt;/p&gt;
&lt;p&gt;  Do you mean something like:&lt;/p&gt;
&lt;p&gt;  if (x &amp;lt; 10) print(&quot;0&quot;,x)&lt;/p&gt;
&lt;p&gt;BTW: my perl is shaky, so I&#039;m hoping Ken will correct the syntax if it&#039;s wrong &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;vinny&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Oct 2000 16:02:08 +0000</pubDate>
 <dc:creator>Vincent Puglia</dc:creator>
 <guid isPermaLink="false">comment 1072462 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/date-function#comment-1072437</link>
    <description> &lt;p&gt;Hi Vincent,&lt;/p&gt;
&lt;p&gt;Thanks for the tip but I eventually worked out a Perl sub routine.  The only thing I&#039;m stuck on now is displaying the date correctly.  Well, I can bluff a way around it but was wondering whether anyone knew the easiest/proper way of displaying integers in two figures.  ie: 1 to &quot;01&quot; and 2 to &quot;02&quot;?&lt;/p&gt;
&lt;p&gt;Denise &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sun, 08 Oct 2000 21:28:11 +0000</pubDate>
 <dc:creator>Denise</dc:creator>
 <guid isPermaLink="false">comment 1072437 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/date-function#comment-1072418</link>
    <description> &lt;p&gt;Hi Denise,&lt;/p&gt;
&lt;p&gt;  Don&#039;t really remember the exact syntax, but in javascript something like:&lt;/p&gt;
&lt;p&gt;var myMSec = myDate.getMilliseconds(); // myDate is 10/3/00 in date format&lt;br /&gt;
var myDaysinMSec = numOfDays * (60 * 60 * 24 * 1000)&lt;br /&gt;
var totalMsecs = myMSec + myDaysinMSec;&lt;br /&gt;
var newDate = setTime(totalMsecs);&lt;/p&gt;
&lt;p&gt;I&#039;ll check later tonight, but if someone knows for certain, please slap me over the head and correct the code.  Thanks&lt;br /&gt;
Vinny&lt;/p&gt;
 </description>
     <pubDate>Sat, 07 Oct 2000 20:04:25 +0000</pubDate>
 <dc:creator>Vincent Puglia</dc:creator>
 <guid isPermaLink="false">comment 1072418 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
