Managing open and closed menus on custom accordion navigation |
here's a way:
$('.has-submenu > a').on('click', function (e) {
e.preventDefault();
// slide up currently open except if click
// occurs within an already open menu
if ($(this).closest('.nav-open').length === 0)
{
$('.nav > .nav-open').removeClass('nav-open').find('> ul >
li').slideUp();
}
// give the <li> the "nav-open" class, then slide the <li>
grandchildren
$(this).parent().toggleClass('nav-open').find('> ul >
li').slideToggle();
});
http://jsfiddle.net/JqJce/6/
I'm setting the nav-open class on the <li> parent of the <a> vs
on the <a> itself
Also updated this CSS:
.nav-open > a:after {
content:' - ';
}
|
MongoDb opening hours Schema and query for open/closed |
Instead of using actual hours, rather store your time as 0 - 1440, each
number being an increment of a minute. Then you'll be able to use $gte and
$lte.
So you'd have:
hours: {
mon: {open: 570, close: 1080 },
tue: {open: 570, close: 1050 },
...
}
That's the strategy that I'm using in my app. Of course there are slightly
more efficient ways, like storing all the hours for the week in a single
array, but your approach is still good.
|
how to select datetime near 3 hours in mysql |
Use INTERVAL
SELECT * FROM articles
WHERE expires BETWEEN NOW() AND NOW() + INTERVAL 3 HOUR
the BETWEEN is used to check that expiration time is
(1) in the future (filter out already expired)
and (2) within the next 3 hours
|
Converting TimeSpan Hours to DateTime |
It returns "02" when I try it.
The "dd" format makes it put leading zeroes if necessary, but you have
failed to account for this in your Is.EqualTo("2")
Therefore your assertion fails (but you mistakenly thought that it was
returning 3).
I tested this by copy/pasting your code into a Console app:
var _ts = new TimeSpan(2, 1, 30, 10);
var format = "dd";
var returnedVal = _ts.ToString(format);
Console.WriteLine(returnedVal); // Prints "02"
[EDIT] Aha! Now I know what you've done. Your code is actually like this:
var _ts = new TimeSpan(2, 1, 30, 10);
var format = "dd";
DateTime formatDateTime = new DateTime(2012, 01, 01);
var conversionResult = formatDateTime + _ts;
string result = conversionResult.ToString(format);
But note what the type of conversionResult i
|
All Junit Test cases fail due to datetime format |
You have note shared your code but it seems the problem is that you may be
using java.util.Calendar in your code, which is a timezone dependent api
and may generate different results on different machinnes running in
different timezone. If you have choice to change then you should consider
using java.util.Date, as it is timezone-independent
|
DateTime.Today returns wrong Hours / minutes |
Use DateTime.Now:
DateTime.Now.ToString("dd-MM-yyyy_HH-mm_tt");
DateTime.Today gives you the date part of current time with the time
component set to 00:00:00.
See msdn documentation.
|
How to Parse a DateTime String to Support 24 hours timing? |
Simple enough - change the hh to HH.
hh is for 12 hour clocks, HH for 24 hours, as can be seen in the
documentation for Custom Date and Time Format Strings.
|
subtract two datetime fields return wrong total of hours value |
you just do
double res = (y - x).TotalHours;
because c# already knows so subtract to dateTime types and return the
result as a timeSpan
the result is 0.0775 because the difference is 279 seconds. divide by 60
(to minutes) is 4.65 minutes, divide by 60 again for hours is 0.0775 as you
get.
|
my datetime recorded in my DB shift of 2 hours compared to my javascript variable |
Here is my implementation:
function today() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var h = today.getHours();
var m = today.getMinutes();
var yyyy = today.getFullYear();
if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm }
today = dd + '/' + mm + '/' + yyyy + ' ' + h + ':' + m;
return today;
};
var now = moment.utc(today(), "DD/MM/YYYY hh:mm").toDate();
myObservable(now);
This time, the variable now contains: Sat Jun 08 2013 23:08:00 GMT+0200
(Romance Daylight Time)
And the value in my database is 2013-06-08 21:08:00.000.
This value recorded in my DB is the real date time for now.
UPDATE
To respond to John, show some code about what exactly comes from the
browser, and how it
|
Format the time portion of a DateTime with leading space for single-digit hours |
string _text = string.Format("{0:h:mm tt}",_start).PadLeft(8, ' ');
should do it.
The single "h" in the Time Format String will make it so that the zero
doesn't show if it is a single digit hour,l and the PadLeft function will
ensure that it is the proper width.
|
How to change a NSDate's day by adding hours? |
Improved:
Create a date component for a single hour, then get the calendar to add
that component to your previously calculated (initial) fire date:
NSDateComponents *hourComponent = [[NSDateComponents alloc] init];
hourComponent.hour = 1;
dateToBeIncremented = [theCalendar dateByAddingComponents:hourComponent
toDate:dateToBeIncremented options:0];
Original (which have issues with time zones):
How about using the date components to organise the date for the first
notification, then using NSDate dateByAddingTimeInterval: to calculate the
subsequent dates by adding a days worth of seconds.
A better alternative may be to create a debate component for a single hour.
Once you have the first fire date, then use the hour date component to
generate the next fire date, then use that one to ge
|
Schema Change Script : Validation and test cases |
I use dbunit for testing database scripts. It's a very fine tool, but
perhaps overly java centric. You can google for similar tools in other
languages.
Personally I use liquibase to manage all changes to my database schemas. It
reduces much of the complexity of database migrations by putting the
database in a known state. I don't have to test for conditions where a
column may or may not exist, because, the entire schema is effectively
under revision control. Database refactoring actions which are destructive
to data, are always tricky to test. The real advantage of using a tool like
liquibase is that it becomes trivial to setup production-like test systems.
|
Calculate number of days,hours,minutes,seconds only working hours |
Forget about date(), strtotime(), time(), etc. function, use DateTime :
Use example :
$from = '2013-09-06 15:45:32';
$to = '2013-09-14 21:00:00';
echo some_func_name($from, $to);
Output :
1 day, 22 hours, 14 minutes, 28 seconds
Function :
function some_func_name($from, $to) {
$workingDays = [1, 2, 3, 4, 5]; # date format = N
$workingHours = ['from' => ['08', '00'], 'to' => ['17', '00']];
$start = new DateTime($from);
$end = new DateTime($to);
$startP = clone $start;
$startP->setTime(0, 0, 0);
$endP = clone $end;
$endP->setTime(23, 59, 59);
$interval = new DateInterval('P1D');
$periods = new DatePeriod($startP, $interval, $endP);
$sum = [];
foreach ($periods as $i => $period) {
if (!in_array($period->form
|
Submission to gerrit fails with "Change is Closed" message |
It is possible that your rebased change B has Change-Id tag of the
abandoned change A. It could have got there during squashing, for example.
If this is so, amend the commit message to remove Change-Id (your local
Gerrit commit hook will then generate a new one) and try pushing again.
|
how to convert python hours to regular hours |
print(datetime.now().strftime('%Y-%m-%d %I:%M:%S %p'))
will print:
2013-06-18 09:47:38 PM
Look at the documentation to find all directives.
|
Can't get php DateTime timezone conversion to work. It doesn't change the time when I change the timezone |
You're passing a string to as the second argument, you should pass an int
(UNIX timestamp)
Try:
return date($timeformat, $utctime->getTimeStamp());
Edit:
Actually, you could use
return $utctime->format("U");
The problem is that you're always returning a new date because you provided
a bad argument. You should check your php.ini and display_errors and
error_reporting so you can see when php warns you about this things
|
Cannot get hours to total over 24, eg 48 hours in hh:mm:ss output |
SELECT USERNAME,
CAST(TotalTimeInSeconds / (60 * 60) AS Varchar) + ':' +
CAST(TotalTimeInSeconds % (60 * 60) / 60 AS Varchar) + ':' +
CAST(TotalTimeInSeconds % (60) AS Varchar) AS TotalHours
FROM #TotalSessionTime
If you want minutes and seconds to always be two digits, you'll have to
left pad them, which would make for an ugly example, but would work fine.
|
Why method now in Python is obtained as datetime.datetime.now instead of datetime.time.now? |
"Now" is a point in time. That means date matters; if it's noon now,
yesterday noon is not also now. (Time of day also matters; 9 AM today is
also not now.) Thus, it makes sense to have a datetime.datetime.now, but
not a datetime.time.now. It could make sense to have a
datetime.time.currentlocaltime or datetime.time.currentutctime, but those
methods don't exist. You could put in a feature request if you want.
|
Finalizing a Cursor that has not been deactivated or closed or database not closed error |
When you are done with the cursor, you need to call Cursor.close(). Leaving
it not closed leads to memory leaks. E.g.:
Cursor cursor = null;
try {
cursor = getContentResolver().query(myUri, MY_PROJECTION, null, null,
null);
if (cursor != null && cursor.moveToFirst()) {
// moar code
}
} finally {
if (cursor != null) {
cursor.close();
}
}
|
Can't change datetime from time() to NOW () |
As the error says:
You have 9 items in your INSERT statement, but only 7 VALUES. The missing
fields should be replaced with "" as andrewsi suggested in the comments.
Formatting the query makes it more evident:
INSERT INTO pm (id, id2, title, user1, user2, message, date_time,
user1read, user2read)
VALUES("'.$id.'",
"'.(intval(mysql_num_rows($req2))+1).'",
"",
"'.$_SESSION['username'].'",
"",
"'.$message.'",
CURRENT_TIMESTAMP())
The correct query should be:
INSERT INTO pm (id, id2, title, user1, user2, message, date_time,
user1read, user2read)
VALUES("'.$id.'",
"'.(intval(mysql_num_rows($req2))+1).'",
"",
"'.$_SESSION['username'].'",
"",
"'.$message.'",
CURRENT_TIMESTAMP(),
"",
"")
Hope
|
Can't change DATETIME format |
Use DATE_FORMAT(date, format):
DATE_FORMAT(s.date,'%d-%m-%Y')
|
Change DataColumn DateTime Format? |
DateTime has no implicit format, it is just a DateTime value. You can
format it as string but then it's a different type.
For example:
SELECT REPLACE(convert(varchar, YourDateColumn, 106), ' ', '-')
How to format datetime & date
From your comment on your question:
I'm using the DataTable to print out an Excel workbook using EPPlus.
All I want to do is change the format of the cells in DateTime columns
before writing the workbook out. As of now, I'm just doing some error
checking then writing the table to a workbook using EPPlus's
LoadFromDataTable method. I can't just loop through the table and
change the String format of the cells in each DateTime column?
Yes, you can format a column in a sheet created via LoaFromDataTable with
EPPlus, use the appropriate range.S
|
DateTime format culture - how to change it? |
I had quite the same problem, as I'm from Romania. Here's my solution:
Views/Shared/DisplayTemplates/Date.cshtml (create folders and file if not
existing)
@model Nullable<DateTime>
@{
DateTime dt = DateTime.Now;
if (Model != null) {
dt = (System.DateTime)Model;
}
@dt.ToString("dd/MM/yyyy",
System.Globalization.CultureInfo.InvariantCulture);
}
Basically, whenever you're using Html.Display or Html.DisplayFor for a
DateTime (nullable, in my example), it will be rendered according to this
template. You can also set up an editor template (where I use jquery ui's
DatePicker). You can read more about MVC templates here
Script referenced in Layout.cs (therefore available in all views)
$.validator.methods.number = function (value, element) {
value = floatVal
|
Application gets closed when terminal is closed, how to stop this? |
Use nohup to prevent child processes from being killed when the terminal
closes.
spawn nohup /usr/bin/firefox https://www.google.com/
I assume there's more to the script, since there's no need to use Expect
just to start firefox.
|
Get a PHP DateTime difference in days, considering midnight as a day change |
a simple solution to this to strip the time or set it to 00:00:00, that
should always give you the desired result:
$date1 = new DateTime("2013-08-07");
$date2 = new DateTime("2013-08-08");
echo $date1->diff($date2)->days;
or
$date1 = new DateTime("2013-08-07 00:00:00");
$date2 = new DateTime("2013-08-08 00:00:00");
echo $date1->diff($date2)->days;
the time doesnt really matter here
|
Change default DateTime format for razor |
There is no thing like default formatting in Razor. When you do this:
<p>@Model.MyDateTimeObject</p> Razor will simply use the
default DateTime.ToString overload to print the date.
This works by the actual culture information, so for example if you want
your example as the default ToString behavior then you should change the
current culture for the actual request. E.g. in global.asax:
protected void Application_BeginRequest()
{
CultureInfo culture =
(CultureInfo)CultureInfo.InvariantCulture.Clone();
culture.DateTimeFormat.ShortDatePattern = "dd.MM.yyyy";
culture.DateTimeFormat.LongTimePattern = "";
Thread.CurrentThread.CurrentCulture = culture;
}
|
Change datetime to simple %m/%d/%Y in database with rails |
Try this:
Add a file to config/initializers with the following code:
Date::DATE_FORMATS[:default]="%m/%d/%Y"
Time::DATE_FORMATS[:default]="%m/%d/%Y %H:%M"
Time::DATE_FORMATS[:db]="%m/%d/%Y"
and see the railcast.
|
Change a string to datetime field in client side |
You can use a date formatting plugin such as http://www.datejs.com/. (Looks
like you'll have to get rid of the time zone name in parentheses yourself.)
Using that library, you can do this:
var input = "Thu May 30 2013 00:00:00 GMT+0530 (India Standard Time)";
input = input.replace(/(.+)/,''); // Get rid of the stuff in parentheses
Date.parse(input).toString("mm/dd/yyyy hh:mm:ss tt"); //"05/30/2013
02:42:00 AM"
|
How to change a groupby DF to a monthly datetime series in Python Pandas |
Create your top data
In [172]: df =
DataFrame(randn(200,1),columns=['A'],index=pd.date_range('2000',periods=200,freq='M'))
In [173]: df['month'] = df.index.month
In [174]: df['year'] = df.index.year
In [175]: df = df.reset_index(drop=True).set_index(['year','month'])
In [176]: df
Out[176]:
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 200 entries, (2000, 7) to (2017, 2)
Data columns (total 1 columns):
A 200 non-null values
dtypes: float64(1)
In [177]: df.head()
Out[177]:
A
year month
2000 7 0.084256
8 2.507213
9 -0.642151
10 1.972307
11 0.926586
This will create a PeriodIndex of monthly freq. Note that iterating over
the index yields the tuples (as integers)
In [179]: pd.PeriodIndex([ pd.Period(
|
Change to a 24 hour format for datetime data in Google Charts |
You need to format the datetimes using a DateFormatter.
// format dates
// ex: "August 5, 2013 1:45 PM" formatted as "05/08/2013 13:45"
var dateFormatter = new google.visualization.DateFormat({pattern:
'dd/MM/yyyy HH:mm'});
dateFormatter.format(data, 0);
You can format the axis labels by setting the hAxis.format option:
var options = {
hAxis: {
format: 'dd/MM/yyyy HH:mm'
}
title: 'price'
};
The date formats support most of the ISO date formatting patterns.
|
Why does converting a Joda DateTime to Calendar and back change the centuryOfEra field and nothing else? |
Joda Time version 2.2 has an isEqual method that compares only the
milisecond, whereas equals compares the milisecond, chronology and
timezone:
DateTime d = new DateTime();
new DateTime(d.toGregorianCalendar()).isEqual(d); // returns true
new DateTime(d.toGregorianCalendar()).equals(d); // returns false, as you
observed
So either the chronology or timezone are not preserved by the conversion to
or from a GregorianCalender. Leave a comment if you'd like me to
investigate further.
|
Datetime Formatting giving it a specific culture doesn't change how day is printed out |
You are a victim of Composite Formatting overload for Console.WriteLine
where you could pass Format string and a series of object to be inserted in
the placeholders of the format string
You need to write in this way
Console.WriteLine(date.ToString("dddd MM-dd-yy",usCultureInfo));
and you get the right day text.
See the specs here DateTime.ToString(format, IFormatProvider)
|
MS Access Alter Statement: change column data type to DATETIME |
Try running these:
ALTER TABLE table1 ADD NewDate DATE
Then run
UPDATE table1
SET NewDate = RecordTime
WHERE RIGHT(RecordTime,4) <> '- ::'
You can then delete the RecordTime and rename NewDate.
I prefer adding a new column just in case there are any issues with the
UPDATE and you can compare the 'cleaned' column and the initial data before
proceeding.
|
How to draw closed spline 3D (closed curve 3d) through unordered list of points3D. How to arrange points3D? |
It sounds like you're looking for the Concave Hull of the data set.
Unfortunately, I don't know of any pre-canned algorithms, but the link
references a paper that another developer was starting from, as well as
some sample code, so maybe that'll help you in the right direction.
|
The underlying connection was closed: The connection was closed unexpectedly wcf service |
The first thing i will do is, instead of returning the full list of
candidates i will return an empty list. If that works fine, then it is very
clear that the size of the data is a problem. To modify the size play with
your binding parameters.
|
Python Thread.start() throws weird exception relating to datetime.datetime |
Your code doesn't show where timeout is coming from. It's not "suddenly
becoming" anything. Whatever your code, at some point previously, a
datetime.datetime was assigned to timeout. Either eliminate that condition,
or handle it appropriately (perhaps by catching the exception).
Update: You're modifying standard library code, which is an awful idea.
Directly or indirectly, you're passing in a datetime.datetime. Use pdb to
figure out where. Run your code in the python console. When you trigger the
exception do import pdb; pdb.pm(), and you'll drop into the debugger at the
site of the exception. You can explore from there.
|
Not valid datetime error due to wrong fomat of datetime in calender extender |
Some Code to catch something like this and don't cause an Exeption:
if (DateTime.TryParse(txtDate.Text, out dateValue))
{
dr["Date"] = dateValue;
}
else
{
Debug.Write("TextBox Value '{0}' isn't a valid datetime.",
txtDate.Text);
}
|
retrieve rows via join and datetime query where datetime is in past AND NOT in future |
I think you need to have a group function.
SELECT DISTINCT `users`.id FROM `users`
LEFT OUTER JOIN `events` ON events.user_id = users.id
LEFT OUTER JOIN `purchases` ON `purchases`.id = `events`.purchase_id
WHERE events.starts_on <= '2013-07-15' or events.starts_on >=
'2013-08-12'
group by `users`.id
having min(starts_on) <= '2013-07-15' and max(starts_on) <
'2013-08-12'
LIMIT 0, 30;
|
CASTing a datetime to string if null value - keeping original datetime formatting |
Replace cast with convert and appropriate style: Convert syntax &
styles, eg:
ISNULL(convert(varchar(20), fd.decision_date, 120), 'PENDING') as facility,
|
populating datetime value from php into Jquery Moble text input datetime-local |
$(document).ready(function() {
$("#datetime-1").val(<?php YOUR CODE ?>);
$("#datetime-2").val(<?php YOUR CODE ?>);
});
Its a bit hacky but it should work, just make sure the format of the date
is what jq mobile is expecting.
|