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. |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
01-13-2023, 03:59 AM | #1 | |
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:
|
|
01-13-2023, 04:50 AM | #2 |
Bollocks
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.
__________________
Interserver unmanaged AMD Ryzen servers from $73.00 |
01-13-2023, 04:51 AM | #3 | |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana.
Posts: 773
|
Quote:
Or just remove the '0' for the year? |
|
01-13-2023, 04:57 AM | #4 |
Bollocks
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.
__________________
Interserver unmanaged AMD Ryzen servers from $73.00 |
01-13-2023, 05:00 AM | #5 |
Bollocks
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));
__________________
Interserver unmanaged AMD Ryzen servers from $73.00 |
01-13-2023, 05:38 AM | #6 |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana.
Posts: 773
|
Okay thanks for the suggestion and assistance, I appreciate it
|
01-13-2023, 07:23 AM | #7 | ||
I'll make you famous
Industry Role:
Join Date: Oct 2002
Posts: 13,947
|
Quote:
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:
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 . |
||
01-13-2023, 11:54 AM | #8 |
making it rain
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 21,858
|
sarettah you are definitely a case study in patience
|
01-13-2023, 07:47 PM | #9 |
I'll make you famous
Industry Role:
Join Date: Oct 2002
Posts: 13,947
|
|
01-14-2023, 04:21 AM | #10 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,217
|
date('M d Y',strtotime("-8 days"));
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
01-14-2023, 04:47 AM | #11 |
Mark Osterholt Sucks Cock
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)); ?> |
01-14-2023, 04:57 AM | #13 |
Mark Osterholt Sucks Cock
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. |