Jump to content

Problem with date


t.bo

Recommended Posts

Hi everybody,

I want to get the month, year and date out of my complete date (when enterred).

Code : [code]<?
$dat = 2006-07-24;

$year = substr($dat,0,2);
$month = substr($dat,3,2);
$day = substr($dat,6,2);

echo "year is $year<br>";
echo "month is $month<br>";
echo "day is $day<br>"

?>
[/code]

It displays incorrect numbers.
What im I doing wrong?

Grtz and thanks in advance
Link to comment
Share on other sites

Or
[code]<?php
$dt = "2006-07-04";
list($year,$month,$day) = explode('-',$dt);
echo "year is $year<br>";
echo "month is $month<br>";
echo "day is $day";
?>[/code]
or
[code]<?php
$dt = "2006-07-24";
echo date('\y\e\a\r \i\s Y\<\b\r\>\m\o\n\t\h \i\s F\<\b\r>\d\a\y \i\s d',strtotime($dt));
?>[/code]

Ken
Link to comment
Share on other sites

Ok thanks guys, helped me a lot.
Now ... I'm making a calendar. The user uploads an event with title and date (ex. 2006-07-24).

Then the title of the current month should output as a title and then the events ordered by date below.

This is my code : [code]<?php
$currentmonth = date("m");

?>
<h1>Agenda</h1>

<table width="100%"  border="1" cellspacing="0" cellpadding="0">

<?php
include('dbconnect.php');
$sql = mysql_query("select * from agenda where monthfield = '$currentmonth'") or die(mysql_error());

while($row = mysql_fetch_array($sql))
{
$event = $row["eventfield"];
$id = $row["idfield"];
$url = $row["urlfield"];
$date = $row["date"];
$month = $row["monthfield"];



echo "<tr><td><h2>$month</h2></td></tr>";
echo  "<tr><td><a href='$url'>$event</a></td>";
echo  "<td>$date<td></tr>";
}
?>
</table>[/code]

1.) I find this code kinda stupid because the user has to enter the number of the month twice. So im looking for the code that the month can be selected from the main date formfield. (2006-[color=green]07[/color]-24) and that that number can be used to output only current month events. I read that the function DATE_FORMAT has to be used?

2.) My current code does not work like it should because it still displays every month and not only the current month.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.