Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 01-13-2023, 03:59 AM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana.
Posts: 773
Php date problem 'Y' displying 1969

Why is this code displaying 'Y' as 1969?

Quote:
<?php

$today = date("d");
$thisMonth = date("M");
$thisYear = date("Y");
echo date("M d Y", mktime(0,0,0, $thisMonth, $today, $today-8));

?>
I'm trying to get it to display: Jan 5 2023 (minus 8 days from today).
__________________
DMCASUITE
BETA Testers Needed.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-13-2023, 04:50 AM   #2
redwhiteandblue
Bollocks
 
redwhiteandblue's Avatar
 
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
Because you have given the mktime() function a negative number for the year value.
redwhiteandblue is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-13-2023, 04:51 AM   #3
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana.
Posts: 773
Quote:
Originally Posted by redwhiteandblue View Post
Because you have given the mktime() function a negative number for the year value.
So I need to take it out of the echo statement and display it within its own echo statement?

Or just remove the '0' for the year?
__________________
DMCASUITE
BETA Testers Needed.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-13-2023, 04:57 AM   #4
redwhiteandblue
Bollocks
 
redwhiteandblue's Avatar
 
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
No, you need to understand what mktime() does and what parameters it expects.

https://www.php.net/manual/en/function.mktime.php

You are giving it a value for the day where it expects a value for the year.
redwhiteandblue is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-13-2023, 05:00 AM   #5
redwhiteandblue
Bollocks
 
redwhiteandblue's Avatar
 
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
It would be far easier to work with timestamps for this.

Code:
echo date("M d Y", time() - (86400 * 8));
redwhiteandblue is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-13-2023, 05:38 AM   #6
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana.
Posts: 773
Quote:
Originally Posted by redwhiteandblue View Post
It would be far easier to work with timestamps for this.

Code:
echo date("M d Y", time() - (86400 * 8));
Okay thanks for the suggestion and assistance, I appreciate it
__________________
DMCASUITE
BETA Testers Needed.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-13-2023, 07:23 AM   #7
sarettah
I'll make you famous
 
Industry Role:
Join Date: Oct 2002
Posts: 13,947
Quote:
<?php

$today = date("d");
$thisMonth = date("M");
$thisYear = date("Y");
echo date("M d Y", mktime(0,0,0, $thisMonth, $today, $today-8));
?>
this is wrong for so many reasons beyond just having your mktime parameters screwed up

how about when your $today-8 is an invalid day value? on the 7th $day-8 comes back as -1

also what is with splitting the date into pieces like that? you were doing that in the database table at one point too.

you are taking your date and converting it to 3 integers and then turning it back into a date, why?

every language has date functions to handle date calculations, php included

https://www.w3schools.com/php/php_ref_date.asp

handling it the way you are doing is basically trying to reinvent the wheel


Quote:
echo date("M d Y", time() - (86400 * 8));
that is a reasonable solution


i prefer to use datetime objects

in php you can add and subtract from a date pretty easily using the datetime object and associated functions

$mydate=date_create(date('Y-m-d',time())); // create the datetime object
date_sub($mydate, date_interval_create_from_date_string("8 days")); // subtract 8 days
echo date_format($mydate,"M d Y"); // display the result

https://www.w3schools.com/php/func_date_date_sub.asp

you could also use date_modify() for this

$date=date_create(date('Y-m-d',time()));
date_modify($date,"-8 days");
echo date_format($date,"Y-m-d");


https://www.w3schools.com/php/func_date_modify.asp



you should, at all times while working on this stuff have a browser window open to php.net and w3schools.com or other coding sites, just my opinion


.
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-13-2023, 11:54 AM   #8
fuzebox
making it rain
 
fuzebox's Avatar
 
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 21,858
sarettah you are definitely a case study in patience
fuzebox is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-13-2023, 07:47 PM   #9
sarettah
I'll make you famous
 
Industry Role:
Join Date: Oct 2002
Posts: 13,947
Quote:
Originally Posted by fuzebox View Post
sarettah you are definitely a case study in patience
I try



.
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2023, 04:21 AM   #10
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,217
date('M d Y',strtotime("-8 days"));
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2023, 04:47 AM   #11
Mr Pheer
Mark Osterholt Sucks Cock
 
Mr Pheer's Avatar
 
Industry Role:
Join Date: Dec 2002
Location: In your AirBNB
Posts: 19,563
The code is displaying 'Y' as 1969 because the third argument passed to the mktime() function is $today-8 instead of $thisYear.

Here is the corrected code:
Code:
<?php

$today = date("d");
$thisMonth = date("m");
$thisYear = date("Y");
echo date("M d Y", mktime(0,0,0, $thisMonth, $today-8, $thisYear));

?>
This will display the date 8 days ago in the format "Jan 6 2023".
Mr Pheer is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2023, 04:54 AM   #12
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana.
Posts: 773
Thank you all for the assistance with this i genuinely appreciate the advice and feedback
__________________
DMCASUITE
BETA Testers Needed.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2023, 04:57 AM   #13
Mr Pheer
Mark Osterholt Sucks Cock
 
Mr Pheer's Avatar
 
Industry Role:
Join Date: Dec 2002
Location: In your AirBNB
Posts: 19,563
It took maybe 30 seconds to copy the post just as it was written, paste it into ChatGPT, wait for the answer, copy that, come to GFY, and paste it.

Learn to use AI or you're getting left behind.
Mr Pheer is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
jan, display, days, minus, displying, date, code, php, helpme, displaying



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.