What this code does: It generates dates based on a single day that is grabbed before ($date). It counts always up one week. E.g. If your start date ($date) is 07.04.2019 it will generate the dates for $final_amount times.  So, if the start of the date is 07.04.2019 and $final_amount is: 5 it will output:  07.04.2019` (handled in separate code, as the first day is excluded in code!) 14.04.2019 21.04.2019 28.04.2019 05.04.2019   The issue with my code: I need to skip the date if it falls into a holiday. So if e.g. 21.04.2019 is a holiday, it should be skipped and replaced with a new date one week later. It should always have the amount $final_amount even if one ore more dates are laying on a holiday. I have no Idea how this could be accomplished, as I am relatively new to PHP.  setlocale(LC_TIME, "de_DE"); //only necessary if the locale isn't already set $date = new DateTime(helper('com://site/ohanah.date.format', array(    'date' =&gt; $event-&gt;start,    'format' =&gt; 'Y-m-d H:i',    'timezone' =&gt; 'UTC' )));  $date_scn = new DateTime(helper('com://site/ohanah.date.format', array(    'date' =&gt; $event-&gt;end,    'format' =&gt; 'H:i',    'timezone' =&gt; 'UTC' )));  $cnt = 2; // start the termin to count at two as the first one is already defined above $raw_ticket_type = $event-&gt;ticket_types-&gt;name; $filter_numbers = array_filter(preg_split('/\D/', $raw_ticket_type)); $filtered_numbers = reset($filter_numbers); $first_occurence = substr($filtered_numbers[0], 0, 1); $final_amount = $first_occurence - 1; // subtract 1 from $first_occurence as it is always one more  for ($i = 0; $i &lt; $final_amount; $i++) { // loop     $date-&gt;add(new DateInterval('P1W')); //add one week     $formatted_time = utf8_encode(strftime("%A, %d. %B %Y, %H:%M", $date-&gt;getTimestamp()));     $formatted_time_scnpart = utf8_encode(strftime("%H:%M", $date_scn-&gt;getTimestamp()));      // This is the modal      echo '&lt;div class="termin-layout"&gt;&lt;span class="termin-number-text"&gt;' . $cnt++ . '. ' . 'Termin' . '&lt;/span&gt; &lt;span class="termin-date"&gt;' . $formatted_time . ' - ' . $formatted_time_scnpart . '&lt;/span&gt;&lt;/div&gt;'; }  echo '&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;';
9353
I have a loop that is doing some error checking in my PHP code. Originally it looked something like this...  foreach($results as $result) {     if (!$condition) {         $halt = true;         ErrorHandler::addErrorToStack('Unexpected result.');     }      doSomething();  }  if (!$halt) {     // do what I want cos I know there was no error }   This works all well and good, but it is still looping through despite after one error it needn't. Is there a way to escape the loop?
111221
I have a custom meta box with a datepicker. The datepicker outputs 2013-01-17 10:00 in my database for an event that is 01-17-2013 at 10pm PST.  $eventlist = new WP_Query(array(     'post_type' =&gt; 'events',     'posts_per_page' =&gt; 5,     'order' =&gt; 'asc',     'orderby' =&gt; 'meta_value',     'meta_key' =&gt; 'datetime',     'meta_query' =&gt; array(         array(             'key' =&gt; 'datetime', // Check the start date field             'value' =&gt; date("Y-m-d H:i:s"),               'compare' =&gt; '&gt;=',              'type' =&gt; 'DATETIME'          )     ), ));   The issue is, at 4pm PST the event disappears, leading me to believe somewhere it is thinking its UTC and making the post go bye bye. Where would i Find this issue and how can i solve it?
62683
How can use non-Gregorian dates and calendars?  I adjust Drupal setting to my native language (fa) and native location (Asia/Theran) but month name and number of years also in Gregorian yet (however there are translated to my native language-persian).  I already use format_date() or date() in theme files, but this function is not locale-aware, which means that it always outputs English language data, such as day and month names and ordinal number suffixes.  I want to show the month names in the native language (e.g. Chinese, Islamic, Hebrew, Farsi/Persian) and use the national calendar (e.g. Irani, Shamsi, Jalali).  I want to understand is there any module or hardcoding solution in Drupal to show dates and calendars in other non-Gregorian calendars.  Any suggestions?
26496
I want to display dates in the format: short day of week, short month, day of month without leading zero but including "th", "st", "nd", or "rd" suffix.  For example, the day this question was asked would display "Thu Oct 2nd".  I'm using Ruby 1.8.7, and  just doesn't seem to do this.  I'd prefer a standard library if one exists.
116296
Anytime I have to handle dates/times in java it makes me sad   I'm trying to parse a string and turn it into a date object to insert in a preparepared statement. I've been trying to get this working but am having no luck. I also get the helpful error message when I go to compile the class.  "Exception in thread "main" java.lang.Error: Unresolved compilation problem:  The method setDate(int, Date) in the type PreparedStatement is not applicable for the arguments (int, Date)"  Eh WTF?  Here is the offending code.  for(int i = 0; i &lt; flights.size(); i++){      String[] details = flight[i].toString().split(":");      DateFormat formatter ;      formatter = new SimpleDateFormat("ddMMyyyy");     Date date = formatter.parse(details[1]);       PreparedStatement pstmt = conn.prepareStatement(insertsql);     pstmt.setString(1, details[0]);     pstmt.setDate(2, date);     pstmt.setString(3, details[2] + "00");     pstmt.setString(4, details[3]);     pstmt.setString(5, details[4]);     pstmt.setString(6, details[5]);     pstmt.setString(7, details[6]);     pstmt.setString(8, details[7]);     pstmt.setString(9, details[8]);     pstmt.executeUpdate();  }
106040
I've been using Javascript's Date for a project, but noticed today that my code that previously worked is no longer working correctly. Instead of producing Feb as expected, the code below produces March.   My code looks something like this:   current = new Date(); current.setMonth(current.getMonth()+1); //If today is Jan, expect it to be Feb now   This code worked everyday up until today. Is this a Javascript bug or am I going about this the wrong way?
23934
I have a custom field called "value_date" where add a date  e.g yyyy/mm/dd  The idea is sort the upcoming dates first in the loop, is possible?  I used a template for custom post taxonomy-event-date.php and this is code in the function, It doesn't work.  Functions.php  add_action('pre_get_posts','search_filter'); function search_filter($query){     if ( !is_admin() &amp;&amp; $query-&gt; is_tax( 'event', 'date' ) ) {         $today = date( 'Y-m-d' );         $query-&gt;set('post_status', 'publish');         $query-&gt;set('meta_value', $today);         $query-&gt;set('meta_key', 'value_date');         $query-&gt;set('orderby', 'meta_value_num');         $query-&gt;set('order', 'ASC');     } }
107508
I am working on a form widget for users to enter a time of day into a text input (for a calendar application). Using JavaScript (we are using jQuery FWIW), I want to find the best way to parse the text that the user enters into a JavaScript Date() object so I can easily perform comparisons and other things on it.  I tried the parse() method and it is a little too picky for my needs. I would expect it to be able to successfully parse the following example input times (in addition to other logically similar time formats) as the same Date() object:   1:00 pm 1:00 p.m. 1:00 p 1:00pm 1:00p.m. 1:00p 1 pm 1 p.m. 1 p 1pm 1p.m. 1p 13:00 13   I am thinking that I might use regular expressions to split up the input and extract the information I want to use to create my Date() object. What is the best way to do this?
48053
I often want to make some quick date calculations, such as:   What is the difference between these two dates? What is the date n weeks after this other date?   I usually open a calendar and count the days, but I think there should be a program/script that I can use to do these kinds of calculations. Any suggestions?
30885
In the PHP manual, to show the syntax for functions with optional parameters, they use brackets around each set of dependent optional parameter. For example, for the  function, the manual reads:  string date ( string $format [, int $timestamp = time() ] )   Where $timestamp is an optional parameter, and when left blank it defaults to the  function's return value.  How do you go about creating optional parameters like this when defining a custom function in PHP?
19427
I have an array in this format:  Array (     [0] =&gt; Array         (             [28th February, 2009] =&gt; 'bla'         )      [1] =&gt; Array         (             [19th March, 2009] =&gt; 'bla'         )      [2] =&gt; Array         (             [5th April, 2009] =&gt; 'bla'         )      [3] =&gt; Array         (             [19th April, 2009] =&gt; 'bla'         )      [4] =&gt; Array         (             [2nd May, 2009] =&gt; 'bla'         )  )    I want to sort them out in the ascending order of the dates (based on the month, day, and year). What's the best way to do that?  Originally the emails are being fetched in the MySQL date format, so its possible for me to get the array in this state:  Array [     ['2008-02-28']='some text',     ['2008-03-06']='some text' ]   Perhaps when its in this format, I can loop through them, remove all the '-' (hyphen) marks so they are left as integars, sort them using array_sort() and loop through them yet again to sort them? Would prefer if there was another way as I'd be doing 3 loops with this per user.  Thanks.  Edit: I could also do this:  $array[$index]=array('human'=&gt;'28 Feb, 2009',                    'db'=&gt;'20080228',                    'description'=&gt;'Some text here');   But using this, would there be any way to sort the array based on the 'db' element alone?  Edit 2: Updated initial var_dump
115374
I'm trying to write a stored procedure to select employees who have birthdays that are upcoming.    SELECT * FROM Employees WHERE Birthday &gt; @Today AND Birthday &lt; @Today + @NumDays  This will not work because the birth year is part of Birthday, so if my birthday was '09-18-1983' that will not fall between '09-18-2008' and '09-25-2008'.    Is there a way to ignore the year portion of date fields and just compare month/days?   This will be run every monday morning to alert managers of birthdays upcoming, so it possibly will span new years.    Here is the working solution that I ended up creating, thanks Kogus.    SELECT * FROM Employees  WHERE Cast(DATEDIFF(dd, birthdt, getDate()) / 365.25 as int)     - Cast(DATEDIFF(dd, birthdt, futureDate) / 365.25 as int)  &lt;&gt; 0
110322
I have the Date module installed on Drupal 7 (version 7.x-2.5) and I am attempting to disable the selection of past dates within the date popup.  $form['ratesDateSelect'] = array(     '#title' =&gt; 'Arrival Date',     '#type' =&gt; 'date_popup',     '#default_value' =&gt; '',     '#size' =&gt; 21,     '#maxlength' =&gt; 100,     '#date_flexible' =&gt; 0,     '#date_year_range' =&gt; (date('Y')) . ':+5',     '#attributes' =&gt; array('autocomplete' =&gt;'off','readonly' =&gt; 'readonly'),     '#description' =&gt; '',     '#value' =&gt; array('date' =&gt; $date),     '#date_format' =&gt; 'D d M Y',     '#required' =&gt; FALSE, );   I have limited the popup to return this year and five years into the future, but I also need to restrict it so that people cannot select past days.  I have managed to do this in another project using pure javascript, using the datepicker param: minDate: 0
40338
Almost everywhere outside the United States, when short dates, e.g. 01/02/2013, are shown on computer screens, the user can't be sure whether the first two digits represent the day or the month. Is it January second or February first?  This is a big problem for people outside the United States, as they encounter both formats regularly, and can't know if the system has adapted to their locale, or has stuck with the American format. But I assume American users see mostly the American format (because many, if not most, information systems are built by or for Americans). What I'm curious about is whether American users also are confused in this scenario?  If you can point to some evidence or research, great. If not, I'll settle for your knowledgeable experience.  Note: I'm not asking for the wonderful solution of naming the month, e.g. May 21, 2013. I'm asking about the cases where a short date format has to be used.
81419
Is it possible to use the =today() function (or something else) to insert the current date but then not update each time the file is opened?  I want to create a numbers template for my invoices. I'd like it to auto fill invoice date and date due then, when I save the document, store the values, not the function.
46612
Given a week number, e.g. date -u +%W, how do you calculate the days in that week starting from Monday?  Example rfc-3339 output for week 40:  2008-10-06 2008-10-07 2008-10-08 2008-10-09 2008-10-10 2008-10-11 2008-10-12
98639
Here is my scenario:  I have to populate list with dates and some metadata of upcoming events for the following year in my Excel application. Some of the events are occurring on the same day each month, e.g. the 3rd day of month.  So the question is:  Is there any function so that I can add one month to given date, like:  cell A1: 1/23/2013 cell A2: 2/23/2013 cell A3: 3/23/2013   What did not work: Apparently A3=$A2+30 produces 3/25/2013 which is wrong.