473,408 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Findin the end date of the given date

110 100+
I have date in the format 200901(YYYYMM FORMAT)
now I want to find the end date in the format(yyyy-mm-dd)
Apr 3 '09 #1
5 1683
Markus
6,050 Expert 4TB
Care to explain a little more? I don't see a question.
Apr 3 '09 #2
TheServant
1,168 Expert 1GB
WHere do you get the original format from? If your starting format is simply numbers I think the string will need to be split (explode() or something) into it's year and month and then you will have to re-declare it as a date so you can use PHP's built-in date format function.
Apr 5 '09 #3
dlite922
1,584 Expert 1GB
I'm no mind reader either but I could tell he's got only a month in the first format and by "end date" s/he means the last day of the given month.

Here's the code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $firstDate = "200905"; // example may is 31 days, should return 2009-05-31
  3.  
  4. // Get the month and year
  5. $year = substr($firstDate,0,4); 
  6. $month = substr($firstDate,5,2); 
  7.  
  8. // get a TimeStamp of the first day
  9. $firstDateTS = mktime(0,0,0,$month,1,$year); 
  10.  
  11. // get the last day of that month. 
  12. $day = date("t",$date);
  13.  
  14. // convert it to a timeStamp again 
  15. $endDateTS = mktime(0,0,0,$month,$day,$year); 
  16. $endDate = date("Y-m-d",$endDateTS); 
  17.  
  18. // OR just print it
  19. $endDate = "$year-$month-$day"; 
  20.  
  21.  
  22. echo $endDate; 
  23.  
  24.  

Hope that helps,




Dan
Apr 7 '09 #4
dlite922
1,584 Expert 1GB
@Markus
Technically, you're right; however the OP did declare what s/he wanted...in as grammatically correct way as s/he could.
Apr 7 '09 #5
numberwhun
3,509 Expert Mod 2GB
@dlite922
While I agree that there was no real question and also agree with your solution dlite, I also see where the OP could be asking how to figure out what the day referred to is, which would be a bit impossible without being told what the day is.

Regards,

Jeff
Apr 7 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
8
by: Benny Chow | last post by:
Hello, I need help in writing a SQL statement in MS SQL Server 2000 to select the latest date (i.e., the date closest to or equal to the current date) for a given date. For example, in a...
2
by: sandy | last post by:
Hello, I am trying to automate a date. When typing in the issue date I want it to automatically calculate 6 months fronm the issue date and give me the Expiration date. Following is code that I am...
0
by: Lee Harr | last post by:
I wrote a function to return the first date of a given week (and a few related functions) : -- return the first date in the given week CREATE or REPLACE FUNCTION week_start(integer, integer)...
2
by: johndcal | last post by:
Hello All, I have a date value that I pull from a .csv file. After reading the file and storing the values in an array the value of the date could be found in $array, for example....
7
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the...
6
by: Jana | last post by:
Greetings Access Gurus! I am working on an app to send batch transactions to our bank, and the bank requires that we place an effective date on our files that is 'one business day in the future,...
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
10
by: Andrew | last post by:
Having trouble with some date computations. I need to get the date of a specific day within a month - the 1st Thursday or the 2nd Monday, etc. I found an article (...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.