Skip to content
WJunction - Webmaster Forum

$_GET date function

Status
Not open for further replies.
hi

i use this :

$date_new=$_GET['year']."-".$_GET['month']; from a form and i used to display the value like this :

<b>Captured Date :</b> <?php echo $date_new; ?>

Its working fine, how ever the output it like = 2013-01. I want it to be 2013-Jan

How can i use dateformat in this code?

Thanks
 

5 comments

If you're using $_GET to pass data to your script, and echo it like you are, you're opening yourself up to a world of exploitation. $_GET['month'] could be tainted with JavaScript and/or a crafty image/iframe hack allowing for cross scripting. I hope there's some form of validation before this code is reached.

All that aside, use mktime to create a timestamp and date to form the abbreviated representation of the month.

Code:
$month = date( 'M', mktime( 0, 0, 0, $_GET[ 'month' ], 10 ) );

$date_new = $_GET['year'] . "-" . $month; 

<b>Captured Date :</b> <?php echo $date_new; ?>

Should work.
 
Status
Not open for further replies.

About the author

E
Established Member · Joined
I'm a Webmaster as well as Sys Admin Coding
136
Messages
3
Reactions
18
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom