473,548 Members | 2,697 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 1299
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
10589
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 cbx_ccjDateNone.Checked = True then dateCCJApprovedDate = ctype("", DateTime) else dateCCJApprovedDate =...
18
2116
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 = Convert.ToDateTime(ddate)
1
4587
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 "dd/MM/yyyy" input as "01082003" convert to date value as, 01 Aug 2003 Example, User Defined Date Format as "yyyy,dd,MM"
2
3265
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 properly because it displays in the document.write method. Create a simple page and paste the below in the code-behind (ASP.NET 1.1-SP1) using...
6
5625
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 want to combine this with the date value, so that I can store it in a single field in the database. How can I combine these two values into one ?
0
1239
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 TextBox1.Text = Calendar1.SelectedDates.ToString(); in page load event but while running nothing is displayed. and also after getting the date in the textbox...
3
35981
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. Is there any manipulation so that I can find out the date entered in
2
2557
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 not the same". I provide example coding below to help you all understand. Please help me, it urgent.... Private Sub Button1_Click(ByVal sender As...
3
3264
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 trying to sort them by the date modified field. So what's the problem, right? Well, obviously Sep 14, 2008 is before Nov 14, 2008, but when doing...
9
3532
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 this happens. This is my part of code given below. <%@ Language=VBScript%> <%Option Explicit%> <html> <head> <title>SABF</title>...
0
7444
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7954
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5367
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5085
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3497
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
755
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.