w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to use culture for changing the datetime format
First, you don't need to actually change the culture if you want to parse or convert dates with a given CultureInfo, so this is unnecessary: Thread.CurrentThread.CurrentCulture = ci; You can simply use the DateTime.Parse overload that accepts the culture: DateTime dt = DateTime.Parse(fromdate, ci); The exception is probably raised at Convert.ToDateTime("d",ci); since d is not a valid date ;) Maybe FROM_DATE is a string property and you actually want to convert the datetime to a short-date-string, then you could either use: _DivAPath.FROM_DATE = dt.ToString("d", ci); or _DivAPath.FROM_DATE = dt.ToShortDateString(); // uses the current-culture

Categories : Asp Net

How to convert .NET DateTime.Ticks value into DateTime in SQL Query?
See this answer: Declare @TickValue bigint Declare @Days float Set @TickValue = 634024345696365272 Select @Days = @TickValue * POWER(10.00000000000,-7) / 60 / 60 / 24 Select DATEADD(d, Cast(@Days As int), Cast('0001-01-01' As DATE)) + Cast( (@Days - FLOOR(@Days)) As DateTime)

Categories : SQL

culture for datetime in c#
Use DateTime.TryParseExact: if (DateTime.TryParseExact(dsVchRecord.Tables[0].Rows[0]["Date"].ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out _dtVoucherDate)) //the rest of it

Categories : C#

DateTime.TryParse for any culture
Sorry, but it seems impossible, since datetime could be ambiguous, and that's why misinterpreted e.g. "01/02/03" is 01 Feb 2003 (Russia) 02 Jan 2003 (USA) 03 Feb 2001 (China) see http://en.wikipedia.org/wiki/Date_format_by_country

Categories : C#

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

Categories : C#

Why is it so slow DateTime.TryParse with culture US and AdjustToUniversal
It's because you're creating 4059 objects - specifically in the bit that says new CultureInfo("en-US"). Declare the US CultureInfo object outside of the loop.

Categories : C#

Culture conversion of datetime in javascript/jquery
Working with dates in JavaScript without a helper library is very painful and error prone. Have you tried using Moment.js? It has support for many languages including French (Canada).

Categories : C#

Culture variant DaylightName and StandardName (DateTime formatting)
Thanks to Hans Passant for this answer. Time zone names are stored in the registry, HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionTime Zones key. You'd need a localized version of Windows to see something different.

Categories : C#

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)

Categories : C#

add hour-minute to datetime
you should check strtottime() documentation to add 1 hour simply use strtotime("+1 hour"); you can also use time() + 60*60 There is also method in DateTime object called "add" that you can use. From manual: DateTime::add -- date_add — Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object You can create DateInterval object and add the interval to exsiting DateTime object. To format date you can use format() method on DateTime object. Edited: Simple explode may solve your problem as well. $interval="01:00"; $xp = explode(":", $interval); $time=time() + (int)$xp[0] * 60*60 + (int)$xp[1]*60; echo date("h:ia", $time); Or more object oriented soution $interval="01:00"; $now=new DateTime(); $now->add(new DateInterval("P0000-00-00T$inter

Categories : PHP

C# get whole hour values between 2 datetime objects
The following will return the total hours between the 2 DateTime objects: (datevalue1 - datevalue2).TotalHours And for a custom behavior,such as displaying a list of hours, use a simple custom method on that Timespan created to get a list of hours in your desired format. Code suggestion of the top of my head: public List<String> GenerateHours(DateTime t1,DateTime t2){ if ((t2-t1).TotalHours >24)){ //decide what to do. return null; }else{ var currentHour = t2.Hour; var list = new List<String>(); for (int i=0;i<(t2-t1).TotalHours;i++){ if (currentHour<10){ list.Add("0"+currentHour+":00"); }else if (currentHour>=10){ list.Add(currentHour+":00"); }

Categories : C#

Datetime variable "tics" one hour
A DateTime object has a Kind property. This property says whether the data should be interpreted in UTC (DateTimeKind.Utc) or in the local time zone (DateTimeKind.Local), or whether it is unknown (DateTimeKind.Unspecified). You should use the overload of DateTimeParse that takes a DateTimeStyles parameter, and specify DateTimeStyles.AssumeUniversal or DateTimeStyles.AssumeLocal.

Categories : C#

How to move the datetime to end of day, week or hour
I agree with Andy; that can't be the intended behavior of shift. A cleaner way to shift times to the end of the month is this: from pandas.tseries.offsets import MonthEnd times = Series(times) times.map(lambda x: x + MonthEnd()) But there is no such thing as HourEnd, DayEnd, or WeekEnd. For those cases, how about following this pattern? from pandas.tseries.offsets import Second, Minute, Hour, Day times.map(lambda x: x + Minute(59-x.minute) + Second(59-x.second)) times.map(lambda x: x + Hour(23-x.hour) + Minute(59-x.minute) + Second(59-x.second)) times.map(lambda x: x + Day(6-x.weekday()) + Hour(23-x.hour) + Minute(59-x.minute) + Second(59-x.second)) If you want the last day of the week but not necessarily the last second of that day, then the expression is obviously sim

Categories : Python

minus 1 hour to DateTime using Joda Time
Just use: dateTime.minusHours(1) This is documented in the API. Note that DateTime objects are immutable, so the operation alone has no effect. You need to assign the result of this method to a new object (or replace itself): dateTime = dateTime.minusHours(1); As to how to obtain a Period out of the difference between two DateTimes, you must first go through an Interval: Period period = new Interval(begin, end).toPeriod(); Link to a SO post explaining why there is both Period and Interval. Side note: Joda Time uses a LOT of indirections in its API; as such reading the Javadoc not only requires one to read the methods for one class, but also look at the list of inherited methods from all the inherited abstract classes/interfaces; for instance, a DateTime is also a ReadableInstant

Categories : Java

Rails 4.0.0 DateTime.strptime need 12 hour no-padding
It seems to be parsing fine, using the %l option. 2:17 AM > DateTime.strptime("8/13/2013 2:17 AM", "%m/%d/%Y %l:%M %p") => Tue, 13 Aug 2013 02:17:00 +0000 2:17 PM > DateTime.strptime("8/13/2013 2:17 PM", "%m/%d/%Y %l:%M %p") => Tue, 13 Aug 2013 14:17:00 +0000

Categories : Ruby On Rails

datetime.date.fromtimestamp: ignores hour and minute
You are creating date objects, not datetime. Dates ignore all time information. Use datetime objects instead if you want to preserve the time component: >>> from datetime import datetime >>> datetime.fromtimestamp(1339119900000/1e3).strftime('%Y-%m-%d %H:%M') '2012-06-08 02:45' >>> datetime.fromtimestamp(1339120800000/1e3).strftime('%Y-%m-%d %H:%M') '2012-06-08 03:00'

Categories : Python

Converting DateTime from specific timezone to UTC - missing hour?
Yes there is a dalylight saving applied. See Wikipedia Places that use Eastern Standard Time (EST) when observing standard time (autumn/winter) are 5 hours behind Coordinated Universal Time (UTC−05:00). Eastern Daylight Time (EDT), when observing daylight saving time (spring/summer) is 4 hours behind Coordinated Universal Time (UTC−04:00). The conversion method is correct. Your assumption about the EST timezone is flawed. If your input dates are really EST then the conversion is correct. If that does not meet your expectations you need to check from where your input data comes from and in which timezone it was really entered. If you are dealing with saved dates in a database and you do not know anymore what is correct and what not you are in trouble. In general it

Categories : C#

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.

Categories : Javascript

How to load resources in a different culture than the current thread's culture?
The ResourceManager has an overloaded version of the GetObject() method which accepts a CultureInfo object. So you would create this object based on the culture you want and pass it along: CultureInfo enCulture = new CultureInfo("en-US"); ResourceManager.GetObject("objectname", enCulture);

Categories : Dotnet

Changing time increments on loop, carring over into next hour when not divisible by 60
$increment = 9; $j = 0; for ($i=$startHour; $i <= $endHour; $i++) { for (; $j < 60; $j += $increment) // $j initialized outside of loop { // ... } $j -= 60; // Get start minute for next hour }

Categories : PHP

TextInfo for Neutral Culture - how is the region of the non-neutral culture determined?
Have a look at http://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx Cultures in .Net have an ID where the last 10 bits defines the language while the other bits define the region. for English the language id is 9 and en_US has an ID of 0x0409 - en_GB has 0x0809 so I guess if you don't provide and region it just takes the first according to the ID CultureID = LanguageID + 0x0400 the same fits also for sv-SE and sv-FI

Categories : Dotnet

Converting JSON data 24 hour time to 12 hour with Javascript
You can use momentjs to format the date in the way you prefer. Fist include momentjs http://momentjs.com/ in your project, and then you will be able to do: moment('06-16-2013 16:00:00','MM-DD-YYYY HH:MM:SS').format('MM-DD-YYYY hh:mm:ss a')

Categories : Javascript

javascript time 24 hour to 12 hour with a click button
The javascript Date when initialized using something like var currentDate = new Date(); will hold the current date and time. You can then use the currentDate.getHours() method to get the hours in 24 hour format. Changing this to 12 hour format first involves checking whether the hour is greater than or equal to 12 (in which case the suffix will be PM, otherwise it will be AM). After this you just modulo the hours by 12. The minutes and seconds can be retrieved using currentDate.getMinutes() and currentDate.getSeconds() respectively. Here is a fiddle that demonstrates the above.

Categories : Javascript

Convert 12-hour time format to 24 hour integer?
You can use DateTime.Parse(...) to get a DateTime value, and then reference the .Hour property for a result; int h = DateTime.Parse("10am").Hour; // == 10 int h2 = DateTime.Parse("10pm").Hour; // == 22 DateTime.Parse is pretty liberal in what it allows, but obviously makes some assumptions internally. For example, in the above code, DateTime.Parse("10am") returns 10am on the current date in the current timezone (I think...). So, be aware of the context in which you use the API.

Categories : C#

Preventing Rails 4 migration from changing timestamp to datetime?
You should be able to define a column specifying the type as a string which will just use that type definition in the database rather than applying any rails interpretation on it. The column docs suggest this but also warn "...this will not be database agnostic and should usually be avoided". It appears that in your case that isn't a problem though. So, something like the following should work: t.column "column_name", "timestamp" This is also suggested by this answer : Ruby/Rails - Active Record Db Migration to MySQL - timestamp type? . I wasn't sure that it would still be the case with later versions of rails but it still seems to hold true.

Categories : Mysql

Emacs Org-Mode: Clear non-repeated SCHEDULED time when DEADLINE is repeated
Here's the patch, if you want to apply it yourself. I'll send another copy to the org-mode mailing list. --- a/lisp/org.el +++ b/lisp/org.el @@ -12835,7 +12835,8 @@ This function is run automatically after each state change to a DONE state." (setq type (if (match-end 1) org-scheduled-string (if (match-end 3) org-deadline-string "Plain:")) ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0)))) - (when (string-match "\([.+]\)?\(\+[0-9]+\)\([hdwmy]\)" ts) + (if (not (string-match "\([.+]\)?\(\+[0-9]+\)\([hdwmy]\)" ts)) + (org-remove-timestamp-with-keyword org-scheduled-string) (setq n (string-to-number (match-string 2 ts)) what (match-string 3 ts)) (if (equal what "w") (setq n (* n 7) what "d"))

Categories : Emacs

Query data for hour by hour report
SELECT DATEPART(hh, DateCreated) AS hour, sum(Units) Units FROM orders WHERE DateCreated >= '6/14/2013' AND DateCreated < '6/15/2013' GROUP BY DATEPART(hh, DateCreated) Read more about DATEPART() here. You can of course add more groupings for day, week, whatever you want: SELECT DATEPART(dd, DateCreated) AS day, DATEPART(hh, DateCreated) AS hour, sum(Units) Units FROM orders WHERE DateCreated >= '6/10/2013' AND DateCreated < '6/15/2013' GROUP BY DATEPART(dd, DateCreated), DATEPART(hour, DateCreated)

Categories : SQL

Access repeated item inside ng-repeated directive
You should pass item as attribute to directive created a sample directive http://plnkr.co/edit/l5r6zIc7ncT1XldRuB98?p=preview

Categories : Angularjs

Bulk convert log file date time format from 12 hour clock to 24 hour clock for mySQL database
If you want to do that on db side and you use MySql you can read it with STR_TO_DATE() and either use it as a datetime value INSERT INTO log (`Site_Name`, `number_of_clicks`, `date`, `Interaction_Type`) SELECT 'site1', 10, STR_TO_DATE('10/05/2013_2:00PM', '%d/%m/%Y_%l:%i%p'), 1; or UPDATE log SET date = STR_TO_DATE(str_date, '%d/%m/%Y_%l:%i%p'); assuming that date column is of type datetime, and str_date column contains string values in 12h format. or if for some reason you store it as VARCHAR and really need to format it as DD/MM/YYYY_14:00 then you can use DATE_FORMAT() DATE_FORMAT(STR_TO_DATE('10/05/2013_2:00PM', '%d/%m/%Y_%l:%i%p'), '%d/%m/%Y_%k:%i') which will produce | NEWDATE | -------------------- | 10/05/2013_14:00 | To update in-place UPDATE log SET

Categories : PHP

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.

Categories : Python

How to convert 3 digit 24 hour time to 12 hour clock with joda-time?
@The New Idiot is right, the docs of Joda state that Shorter numbers are zero-padded to this amount. So "h" only should be padded whereas "hh" will not. Also, you should consider using a long for storing time, more than int. SQL Date is also a good choice.

Categories : Java

How can I express 24 hour time as 12 hour time when using timestamp without timezone in PostgreSQL 9.1?
User to_char(): SELECT to_char('2013-06-10 00:43:30'::timestamp, 'DD/MM/YYYY HH12:MI:SS PM') I added PM to make the output unambiguous. Consider available patterns in the manual.

Categories : Postgresql

How to change hours data from 24-hour format to 12-hour format?
Try this: //Char sequence for a 12 hour format. CharSequence DEFAULT_FORMAT_12_HOUR = "hh:mm a"; //Char sequence for a 24 hour format. CharSequence DEFAULT_FORMAT_24_HOUR = "kk:mm"; //date is the Date object. Look for more functions in format. DateFormat.format(DEFAULT_FORMAT_12_HOUR, date); Let me know if it works. If you have any issue check the Date you are sending. //This should give you the default time on the device. To show that it works. DateFormat.format(DEFAULT_FORMAT_12_HOUR, Calendar.getInstance());

Categories : Android

Creating a cron job to run at hour mark and half hour mark for specific hours on specific day of week
Your cronjob will run at 21.30 as well. To avoid it, you'd better split it in two pieces: 00,30 18-20 * * 1,4 # 1800, 1830, 1900, 1930, 2000, 2030 00 21 * * 1,4 # 2100

Categories : Linux

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.

Categories : Python

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); }

Categories : C#

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,

Categories : SQL

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;

Categories : Mysql

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.

Categories : PHP

MVC : Binding datetime value (bootstrap datetime picker) from view to model
You need to give the input tag a name that corresponds to a property in your model, like this: <input name="DateEntered" data-format="dd/MM/yyyy HH:mm:ss PP" type="text"/>

Categories : Asp Net Mvc



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.