473,503 Members | 12,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting string form of date value

Claus Mygind
571 Contributor
I need the string form of a date minus 6 days. This is driving me crazy

Expand|Select|Wrap|Line Numbers
  1. $a_Date_String = '20140809';
  2.  
  3. //this works fine
  4. $Week_Ending = date ("Y-m-d", strtotime($a_Date_String));
  5.  
  6. $Week_Begin = new DateTime($a_Date_String);
  7. $Week_Begin->sub(new DateInterval('P6D'));
  8.  
  9. /*
  10. I now have a string for $Week_Ending "2014-08-09", 
  11. but the $Week_Begin is a date object
  12.  
  13. How do I extract "2014-08-03" from the $Week_Begin
  14.  
  15. I want to use the string value in my query on the MySQL table like this. 
  16. */
  17. $sql = 'select '.$cSelect.' from '.$cFrom.' where workDay between " '.$Week_Begin.'" and "'.$Week_Ending.'" ' order by '.$cOrderBy;
  18.  
Aug 14 '14 #1
2 1291
Claus Mygind
571 Contributor
Ok after much testing and searching on the net, I finally found the not so intuitive solution
Expand|Select|Wrap|Line Numbers
  1. $a_Date_String = '20140809';
  2.  
  3. $Week_Ending = date ("Y-m-d", strtotime($a_Date_String));
  4.  
  5. $Week_Begin = new DateTime($a_Date_String);
  6. $Week_Begin->sub(new DateInterval('P6D'));
  7.  
  8. //you would think they would have a timetostr function instead of 'format'
  9. $Week_Begin = $Week_Begin->format('Y-m-d'); 
  10.  
  11.  
Aug 14 '14 #2
Dormilich
8,658 Recognized Expert Moderator Expert
look like it’s for a DB. you could also make the calculation there.
Aug 15 '14 #3

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

Similar topics

5
10587
by: darrel | last post by:
I have the following right now to enter a date into SQL getting the data from some pull down menus: ------------------------------------------------- dim dateCCJApprovedDate as DateTime if...
18
2108
by: David Gacek | last post by:
I've tried several different ways all with the same reults. Invalid date Dim ddate As String ddate = "11/22/2004" Dim TryToConvert As Date = Date.Parse(ddate) Dim TryToConvert2 As Date =...
1
4577
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
2
3262
by: xenophon | last post by:
I added a Hidden Form Field to a form in the code behind. The value is being set in JavaScript client-side, but it is not persisting to the server in the PostBack. I know the value is being set...
6
5618
by: Aussie Rules | last post by:
Hi, I have a datepicker that show a calender. The user picks a date and the time component is always 00:00. I then have a drop down that provides a list of times, (10:00, 11:00 etc), and I...
0
1229
by: salo | last post by:
Hi ........Im working with c# and asp.net and i have two calendar control in my form and i want the cliked date value to be get displayed in the textbox. i gave the code as ...
3
35955
by: Bharathi | last post by:
Hi, I got strucked with reading date value from excel file using C#.NET. For Jan-2000 the value I am getting is 36526.0. For all other dates also I am getting some double value like this. ...
2
2552
by: taufik | last post by:
Hi, I have problem with my simple program. Actually, I try to store date value in form of date format (mm/dd/yyyy). I got message that inform me "number of query values and destination fields are...
3
3259
by: kronus | last post by:
I'm receiving an xml file that has a child called modified and it represents a date value in the form of a string -- Nov 14, 2008 -- and in my app, I have items associated with each object and I'm...
9
3526
vikas251074
by: vikas251074 | last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why...
0
7193
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
7316
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...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
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,...
1
4992
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
4666
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.