Jump to content

Sudden substr issue


swatisonee

Recommended Posts

I have been using

[code]$Month = substr($visit_date, 6, 2);[/code]

for all my forms to extract 09 from say 2006-09-08  .  However, i have just realised that this month ie November , date 2006-11-20 is returning -1 and not 11 .

Why could this be and what should i change it to ?

Thanks !
Swati
Link to comment
https://forums.phpfreaks.com/topic/27961-sudden-substr-issue/
Share on other sites

If you have the date in that format, why use substr()? You can used a combination of the [url=http://www.php.net/date]date()[/url] and [url=http://www.php.net/strtotime]strtotime()[/url] functions:
[code]<?php
$visit = '2006-11-20';
$Month = date('m',strtotime($visit));
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/27961-sudden-substr-issue/#findComment-127905
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.