logo
down
shadow

Cast-or-convert yyyy-mm-dd to dd-mon-yyyy am/pm


Cast-or-convert yyyy-mm-dd to dd-mon-yyyy am/pm

By : learnasigo
Date : November 20 2020, 04:01 AM
Any of those help First of all - the best advice I can give you is to stop using string representations of DateTime values.
There's only one place where it's good to use a string representation of a dateTime and that's at the presentation level - the UI that use the data.
code :
DECLARE @DateString varchar(30) = '2018-12-07 13.00.54.984000'

SELECT  CAST(STUFF(STUFF(@DateString, 17, 1, ':'), 14, 1, ':') AS DateTime2);
SELECT FORMAT(@DateTime, 'dd-MMM-yy hh.mm.ss.fffffff tt')
DECLARE @DateString varchar(30), @Date DateTime2;

SET @DateString = '2018-12-07 13.00.54.984000'

SELECT  @Date = CAST(STUFF(STUFF(@DateString, 17, 1, ':'), 14, 1, ':') AS DateTime2)

SELECT FORMAT(@Date, 'dd-MMM-yy hh.mm.ss.fffffff tt') As Result    
07-Dec-18 01.00.54.9840000 PM


Share : facebook icon twitter icon
Convert or cast varchar MM/DD/YYYY data into datetime MM/DD/YYYY

Convert or cast varchar MM/DD/YYYY data into datetime MM/DD/YYYY


By : erica price
Date : March 29 2020, 07:55 AM
it helps some times To do a proper range query, you can convert from your bad regional formats in a predictable way, and then use an open-ended range. Now this doesn't protect you from someone entering 06/08/2013 and meaning August 6th instead of June 8th, but if you support free text entry, that's a risk you'll have to take.
code :
DECLARE @s DATETIME, @e DATETIME;

SELECT @s = CONVERT(DATETIME, '03/13/2013', 101),
       @e = CONVERT(DATETIME, '03/26/2013', 101);

SELECT <cols>
FROM dbo.table_name
  WHERE datetime_column >= @s
  AND datetime_column < DATEADD(DAY, 1, @e);
PHP preg_replace for All Types of Year Formats (YYYY, YYYY-YYYY, YYYY - YYYY)

PHP preg_replace for All Types of Year Formats (YYYY, YYYY-YYYY, YYYY - YYYY)


By : Cyle Dawson
Date : March 29 2020, 07:55 AM
hop of those help? preg_replace_callback() will let you validate/extract your targeted substrings and make conditional replacements in one pass.
A
must be written before all year/year-ranges so long as it is not the very start of the string. The first capture group is \s*, so it will capture zero or more white-space characters before your targeted year/year-range. This element will always exist as [1] in the $m array. The second capture group is the first or only year value. This is required to exist for the callback function to be implemented. This is [2] in the $m array. As for the optional secondary year value, it must follow zero or more white-spaces then a hyphen then zero or more white-spaces. Because there are no capture groups to follow this capture group, php will only generate an element for this group if it is found -- isset() is used to check if [3] exists. Originally, I used \b to ensure that the year values were not substrings of larger digital substrings, but the format of your strings allows the use of white-space matching to confirm an accurate match.
code :
$string = "2007 Chevy Silverado Pickup new body style models 2008-2013 Chevy Silverado All Models 2014 Chevy Silverado 2500HD 3500HD 2007 GMC Sierra Pickup new body style models 2008 - 2013 GMC Sierra All Models 2014 GMC Sierra 2500HD 3500HD 2007-2013 Chevy Tahoe 2007-2013 Chevy Suburban 2007   -   2013 Chevy Avalanche 2007-2013 GMC Yukon Yukon XL Yukon Denali";

echo preg_replace_callback('~(\s*)(19[5-9]\d|20[0-4]\d)(?:\s*-\s*(19[5-9]\d|20[0-4]\d))?(?=\s)~', function($m) {
    //var_export($m);  // un-comment if you want to see each $m array
    //echo "\n---\n";
        return (strlen($m[1]) ? "\n" : "")
                . "<strong>*{$m[2]}"
                . (isset($m[3]) ? " - {$m[3]}" : "")
                . "</strong>";
    },
    $string);
<strong>*2007</strong> Chevy Silverado Pickup new body style models
<strong>*2008 - 2013</strong> Chevy Silverado All Models
<strong>*2014</strong> Chevy Silverado 2500HD 3500HD
<strong>*2007</strong> GMC Sierra Pickup new body style models
<strong>*2008 - 2013</strong> GMC Sierra All Models
<strong>*2014</strong> GMC Sierra 2500HD 3500HD
<strong>*2007 - 2013</strong> Chevy Tahoe
<strong>*2007 - 2013</strong> Chevy Suburban
<strong>*2007 - 2013</strong> Chevy Avalanche
<strong>*2007 - 2013</strong> GMC Yukon Yukon XL Yukon Denali
Cast or convert DD-MON-YYYY AM/PM to YYYY-MM-DD

Cast or convert DD-MON-YYYY AM/PM to YYYY-MM-DD


By : Frédéric Degave
Date : March 29 2020, 07:55 AM
Any of those help Below is one method that converts the date and time portions separately, and then uses DATEADD to combine the results. This assumes the actual time precision is not greater than milliseconds. Note that you need to use datetime2 instead of datetime to avoid rounding to 1/300 milliseconds.
code :
DECLARE @DateTimeString varchar(30) = '07-DEC-18 01.00.54.984000 PM';
SELECT DATEADD(
      millisecond
    , DATEDIFF(millisecond, '', CAST(REPLACE(SUBSTRING(@DateTimeString, 11, 8), '.', ':') + RIGHT(@DateTimeString, 10) AS time))
    , CAST(LEFT(@DateTimeString, 9) AS datetime2)
    );
jQuery masked input - format date as m/d/yyyy or m/dd/yyyy or mm/dd/yyyy or mm/d/yyyy

jQuery masked input - format date as m/d/yyyy or m/dd/yyyy or mm/dd/yyyy or mm/d/yyyy


By : kell
Date : March 29 2020, 07:55 AM
hope this fix your issue I had a similar requirement recently, and the only thing I could find that didn't require me to do a lot of work on tweaking the plugin was to use this modified date masking plugin that is based on the one you mentioned. It seems to be doing the job so far.
If you want to test it out, head to this page.
How to convert date dd/mm/yyyy hh:mm:ss AM to mm/dd/yyyy hh:mm:ss: am throwing invalid cast exception

How to convert date dd/mm/yyyy hh:mm:ss AM to mm/dd/yyyy hh:mm:ss: am throwing invalid cast exception


By : Mouna Karoui
Date : March 29 2020, 07:55 AM
I hope this helps you . What is the type of property cdate? I am assuming that it is of type DateTime and I am also assuming that you are trying to do something like this:
code :
cdate = cdate.ToString("MM/dd/yyyy hh:mm:ss")
cdate = DateTime 
           .ParseExact(cdate, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)
           .ToString("MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
Related Posts Related Posts :
  • SELECT Top (100) a lot faster than Top (1)
  • Unable to enable filestream in sqlserver ubuntu
  • VB.NET SQL Server: Must declare scalar variable
  • SQL Executing store procedure multiple times
  • How to get date from day name?
  • Pivot / Unpivot the following data
  • Tomcat not able to find Microsoft SQL driver class
  • Get the SQL Server Agent job that has run a particular execution of a deployed SSIS package
  • How to set a specific condition to a new Parameter in T-SQL
  • Get the SQL Server version to a variable in bash script
  • Sum values from multiple tables grouping by a common column
  • Getting todays date on WHERE clause
  • Slow WHERE EXISTS in SQL Server
  • Calculating a New Variable
  • SSRS Data-Driven Triggered Email
  • WHERE clause in MDX for Dynamic Management Views
  • How to create filtered index with NOT IN in SQL Server
  • How to split comma separated values stored in XML node and display as individual records Without using function- SQL Ser
  • T SQL Cursor Returning Empty Table
  • Cannot delete rows from a temporal history table
  • T-SQL SUBSTRING with CHARINDEX as Length parameter
  • SSRS Selective Page Break
  • Reading from CosmosDB and write to Azure SQL
  • Case when only executes ELSE statement
  • Convert Row data (Dates ) in Column headers in SQL
  • pyodbc - SQL Server does not exist or access denied problem
  • Read json value in where clause in sql server 2016
  • Join 2 tables VB.NET
  • Query in SQL Server to combine tables
  • EFCore: Query a related entity based on the maximum value in a field in the related entity
  • Problem to combine 2 queries to get single set of results
  • Nested queries results in error 'The multi-part identifier "r.ctripnumber" could not be bound.'
  • SSIS Error "To run a SSIS package outside of SQL Server Data Tools you must install Standard Edition (64-bit) of In
  • How can I set sp_send_dbmail to email the query results?
  • SSRS how to deal with extra rows being created
  • How to set a multi-valued XML attribute using SQLXML modify
  • How to connect to azure SQL server using visual studio
  • Azure Data Studio: Save As CSV
  • "Input string was not in a correct format" Visibility expression error
  • SQL query to search for a record that has a certain text?
  • What a StoredProcedure
  • Connection between J2me and Sql Server 2008
  • How to replay a SQL Profiler trace on different database?
  • SQL Server, result of table as "Column" or "COUNT(Column)" depending on the parameter?
  • 100k Rows Returned in a random order, without a SQL time out please
  • Determine dates by number of days, "what date is 180 days from now
  • Output not displaying - SQL Server
  • CakePHP model useTable with SQL Views
  • Delete from tablename takes abnormally long
  • How do I suppress empty namespaces with FOR XML in Sql Server
  • What changes should be made to SQL Server’s locking architecture to make it more developer friendly?
  • Could not open a connection to sql server
  • How to sort GUID's the SQL Server way using Delphi
  • SQL Server 2008 - how to zip backup files and move to remote server
  • Enumerated types in SQL Server 2008?
  • How to connect SQL Server 2008 Express?
  • Delete SQL Server 2005 records without logging
  • Connect to SQL Server 2008 with TCP/IP
  • Why is my query so slow? (SQL Server 2008 full text search weirdness)
  • How can SCOPE_IDENTITY return null when @@IDENTITY does not?
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org