Jump to content

Recommended Posts

Hello.

 

I have a field in my database which the date is stored as (for example) 25/12/2008 . When this date arrives i want to send an email. The date is stored as a string.

 

I assume i will have to create a cron job to check for the dates, so it will be something like

 

for each recorded find finishdate

parse the date to understandable format?

if $finishdate = todays date

send email code

 

I'm not sure how to parse and check if it's today. Any code or advice?

 

thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/131476-php-date/
Share on other sites

Would be best off saving the date as "date" type (YYYY-MM-DD) in your database - I'm assuming it's MySQL?

 

then, assuming you've queried the database and have the date stored in $row['run_date'] .. you could simply go..

 

if ($row['run_date'] == date("Y-m-d")) {
    // do something!
}

 

Adam

Link to comment
https://forums.phpfreaks.com/topic/131476-php-date/#findComment-682790
Share on other sites

Sorry about the late reply.

 

I'm just testing with this code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

$date=date("06/11/2008");

echo "This is the date, $date <br>
But heres the timestamp of date ".strtotime($date)." 
<br> let formate the date now it in a timestamp ".date("d/m/y",strtotime($date))." ";

$time = time();
$formated=date("d/m/y", $time);


echo "<br/>Today date in a timestamp formate is >$time<
<br> but the date formated is >$formated<";

?>

</body>
</html>

 

This is the date, 06/11/2008

But heres the timestamp of date 1213138800

let formate the date now it in a timestamp 11/06/08

Today date in a timestamp formate is >1225963324<

but the date formated is >06/11/08<

 

The second bit is correct as it has the date the wrong way round than I would like it on the 3rd line of the quote. Any ideas why?

 

Thanks again for your help and advice.

Link to comment
https://forums.phpfreaks.com/topic/131476-php-date/#findComment-683523
Share on other sites

Sorry, but I cannot make and sense out of your post, can you highlight what is wrong, and then tell us how you would like it.

 

If its a formatting problem (aka, the month is in the wrong place), then consider reading this http://uk.php.net/date

 

Here you will find loads of codes that are using within the date function so you can correctly format the date you desire. For example, a date function doesn't have to be as simple as 'd/m/y', it can be very complex, such as 'l jS \of F Y h:i:s A'.

 

ILMV

Link to comment
https://forums.phpfreaks.com/topic/131476-php-date/#findComment-683527
Share on other sites

Sorry, but I cannot make and sense out of your post, can you highlight what is wrong, and then tell us how you would like it.

 

If its a formatting problem (aka, the month is in the wrong place), then consider reading this http://uk.php.net/date

 

Here you will find loads of codes that are using within the date function so you can correctly format the date you desire. For example, a date function doesn't have to be as simple as 'd/m/y', it can be very complex, such as 'l jS \of F Y h:i:s A'.

 

ILMV

 

In my post look at the 'quote'. On the third line the date should be 06/11/2008 not 11/06/2008. Which is something to do with this line of code:

<br> let formate the date now it in a timestamp ".date("d/m/y",strtotime($date))." ";

 

The format set in the code says d/m/y but it's showing m/d/y. Any ideas?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/131476-php-date/#findComment-683544
Share on other sites

Hmm, I have had problems with using date() in the past with issues such as this, I ended up having to write my own function to overcome the problem, it might be a little around the houses, but in some circumstances it will work like a dream.

 

function format_date($timestamp_date='', $result_format='YmdHis') 
{
if($timestamp_date=='')
{	
	// Return if no variables passed
	return;
}
else
{	
	// Split up date and time
	$date_time = split(" ", $timestamp_date); 

	// Split up date
	$date = split("/", $date_time[0]);

	// Split up time
	$time = split("-", $date_time[1]);

	// Compile date into desired format
	$result=date($result_format, mktime($time[0], $time[1], $time[2], $date[1], $date[0], $date[2]));
}

// Return resulting variable to main function
return $result;
}

 

And this is how the function is used:

 

echo(format_date('16/10/2008 23:57:21'));

 

Its worth trying as it might solve your problem.

 

For others, this function needs some work to make it 100%, one thing it does require is the ability to specify what format you send the timestamp via... but please, give me your feedback...

 

ILMV

Link to comment
https://forums.phpfreaks.com/topic/131476-php-date/#findComment-683559
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.