日期格式,单位为dd / MM / yyyy hh:mm:ss

时间:2012-07-29 07:58:55

标签: sql-server sql-server-2008

我需要将日期时间从2012-07-29 10:53:33.010转换为 29/07/2012 10:53:33

我尝试使用

select CONVERT(varchar(20), GETDATE(), 131)

但根据Hijri日历显示日期

11/09/1433 10:53:33:

请帮帮忙?

7 个答案:

答案 0 :(得分:20)

这可以通过以下方式完成:

select CONVERT(VARCHAR(10), GETDATE(), 103) + ' '  + convert(VARCHAR(8), GETDATE(), 14)

希望有所帮助

答案 1 :(得分:8)

get '/*path', to: redirect("/#{I18n.default_locale}/%{path}"),
  constraints: lambda { |req| I18n.available_locales.none? { |locale| req.path.starts_with? locale.to_s } }

实施例 -

scope ':locale', locale: /#{I18n.available_locales.join("|")}/ do
  resources :books
end

get '/*locale/*path', to: redirect("/#{I18n.default_locale}/%{path}")
get '/*path', to: redirect("/#{I18n.default_locale}/%{path}"),
  constraints: lambda { |req| I18n.available_locales.none? { |locale| req.path.starts_with? locale.to_s } }

答案 2 :(得分:3)

您可以合并两种格式:

3   dd/mm/yy   (British/French)
8   hh:mm:ss

根据CONVERT() function,并使用+运算符:

SELECT CONVERT(varchar(10),GETDATE(),3) + ' ' + CONVERT(varchar(10),GETDATE(),8)

答案 3 :(得分:1)

    <?php
// query category 1   
 $type = 'course';
    $args1=array(
      'post_type' => $type,
      'post_status' => 'publish',
      'posts_per_page' => -1,
    'category_name' => 'slug_name' // added the category name enter the slug name as defined in the category
      'caller_get_posts'=> 1);

// query category 2   
 $type = 'course';
    $args2=array(
      'post_type' => $type,
      'post_status' => 'publish',
      'posts_per_page' => -1,
    'category_name' => 'slug_name' // added the category name enter the slug name as defined in the category
      'caller_get_posts'=> 1);

    $my_query = '';
    $my_query = new WP_Query($args1);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();

   $my_query = '';
    $my_query = new WP_Query($args2);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();
    ?>

答案 4 :(得分:0)

这将是varchar,但应根据需要进行格式化。

RIGHT('0' + LTRIM(DAY(d)), 2) + '/'
+ RIGHT('0' + LTRIM(MONTH(d)), 2) + '/'
+ LTRIM(YEAR(d)) + ' '
+ RIGHT('0' + LTRIM(DATEPART(HOUR, d)), 2) + ':'
+ RIGHT('0' + LTRIM(DATEPART(MINUTE, d)), 2) + ':'
+ RIGHT('0' + LTRIM(DATEPART(SECOND, d)), 2)

ddatetime字段或变量。

答案 5 :(得分:0)

import * from 'framework'

答案 6 :(得分:-1)

关于MSDN联机丛书中CAST and CONVERT的章节,您已经错过了一行的正确答案....您可以使用样式号。 121( ODBC规范(以毫秒为单位))获取您正在寻找的结果:

SELECT CONVERT(VARCHAR(30), GETDATE(), 121)

这给了我输出:

2012-04-14 21:44:03.793
根据您更新的问题

更新 - 当然这不会有效 - 您正在转换字符串(这个:'4/14/2012 2:44:01 PM' 只是一个字符串 - 它的日期时间!)到一个字符串......

您需要首先将您拥有的字符串转换为DATETIME那么将其转换回字符串!

试试这个:

SELECT CONVERT(VARCHAR(30), CAST('4/14/2012 2:44:01 PM' AS DATETIME), 121) 

现在你应该得到:

2012-04-14 14:44:01.000

显然,所有零都是毫秒,因为您的原始值并不包含任何....