wwfc_barmy_army Posted November 5, 2008 Share Posted November 5, 2008 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 More sharing options...
Adam Posted November 5, 2008 Share Posted November 5, 2008 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 More sharing options...
redarrow Posted November 5, 2008 Share Posted November 5, 2008 Next time use a int and the time(); function for dates mate................ time(); creates a timestamp If you want to use date then set the database to date, Then use now() in the insert but to be onest time(); php function is better. Link to comment https://forums.phpfreaks.com/topic/131476-php-date/#findComment-682798 Share on other sites More sharing options...
wwfc_barmy_army Posted November 5, 2008 Author Share Posted November 5, 2008 How do i store them as a date. I know i would need to change the field type, but when inserting a value with PHP do i need to do anything special or just make sure what is being input goes in the format YYYY-MM-DD? thanks for your help. Link to comment https://forums.phpfreaks.com/topic/131476-php-date/#findComment-682799 Share on other sites More sharing options...
redarrow Posted November 5, 2008 Share Posted November 5, 2008 <?php $time=time(); $formated=date("d/m/y", $time); echo "Today date in a timestamp formate is >$time< <br> but the date formated is >$formated<"; ?> you can use any off the date formats have a look try them there quite funky... http://uk3.php.net/date Link to comment https://forums.phpfreaks.com/topic/131476-php-date/#findComment-682802 Share on other sites More sharing options...
redarrow Posted November 5, 2008 Share Posted November 5, 2008 check this out reverse lol... <?php $date=date("d/m/y"); 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))." "; ?> Link to comment https://forums.phpfreaks.com/topic/131476-php-date/#findComment-682807 Share on other sites More sharing options...
wwfc_barmy_army Posted November 6, 2008 Author Share Posted November 6, 2008 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 More sharing options...
ILMV Posted November 6, 2008 Share Posted November 6, 2008 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 More sharing options...
wwfc_barmy_army Posted November 6, 2008 Author Share Posted November 6, 2008 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 More sharing options...
ILMV Posted November 6, 2008 Share Posted November 6, 2008 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 More sharing options...
kenrbnsn Posted November 6, 2008 Share Posted November 6, 2008 Dates in PHP are "MM/DD/YYYY". In your example, the first date "06/11/2008" is June 11, 2008 and the second date "11/06/2008" is November 6, 2008. Ken Link to comment https://forums.phpfreaks.com/topic/131476-php-date/#findComment-683595 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.