すいません、VB4しかやってないんです、VBAはやったけど(ぼそ) チラシの裏だって立派な書き込み空間なんだからねっ!資源の有効活用なんだからねっ!とか偉そうに言ってるけど、実は色々と書き残したいだけ

だからなに? どうしろと? くるみサイズの脳みそしかないあやしいジャンガリアンベムスターがさすらう贖罪蹂躙(ゴシックペナルティ)

ホーム 連絡をする 同期する ( RSS 2.0 ) Login
投稿数  632  : 記事  35  : コメント  11659  : トラックバック  143

ニュース


片桐 継 は
こんなやつ

かたぎり つぐ ってよむの

大阪生まれ河内育ちなんだけど
関東に住みついちゃったの
和装着付師だったりするの
エセモノカキやってたりするの
VBが得意だったりするの
SQL文が大好きだったりするの
囲碁修行中だったりするの
ボトゲ好きだったりするの
F#かわいいよF#

正体は会った人だけ知ってるの

空気読まなくてごめんなさいなの


わんくまリンク

C#, VB.NET 掲示板
C# VB.NET掲示板

わんくま同盟
わんくま同盟Blog


WindowsでGo言語
WindowsでGo言語


ネット活動


SNSは疲れました

記事カテゴリ

書庫

日記カテゴリ

ギャラリ

イベント活動

プログラムの活動

おぎわらさんのエントリ、面白そうだったんで、VBでも書いてみた

Imports System.Globalization
Module Module1

  Sub Main()

    Dim s1 As String = "2008/04/09"
    Dim d1 As DateTime = DateTime.Parse(s1)

    Dim s2 As String = "20080409"
    Dim d2 As DateTime = DateTime.ParseExact(s2, "yyyyMMdd", DateTimeFormatInfo.CurrentInfo)

    Dim s3 As String = "2008/04/31"
    Dim d3 As New DateTime
    If DateTime.TryParse(s3, d3) = False Then
      Console.WriteLine(String.Format("{0}は日付のデータではありません", s3))
    End If

    Dim s4 As String = "20080431"
    Dim d4 As New DateTime
    If DateTime.TryParseExact(s4, "yyyyMMdd", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, d4) = False Then
      Console.WriteLine(String.Format("{0}は日付のデータではありません", s4))
    End If

    Dim s5 As String = "2008/02/29"
    Dim d5 As New DateTime
    If DateTime.TryParse(s5, d5) Then
      Console.WriteLine(String.Format("{0}は日付のデータです", s5))
    Else
      Console.WriteLine(String.Format("{0}は日付のデータではありません", s5))
    End If

    Dim s6 As String = "20080229"
    Dim d6 As New DateTime
    If DateTime.TryParseExact(s6, "yyyyMMdd", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, d6) Then
      Console.WriteLine(String.Format("{0}は日付のデータです", s6))
    Else
      Console.WriteLine(String.Format("{0}は日付のデータではありません", s6))
    End If

  End Sub

End Module

うるう年チェック付だよーん。
思ったのだけれど、本当にC#とVBって似てるよねぇ、つかほとんど、一緒に見える(笑)

で、ふと思ったこと。
http://bbs.wankuma.com/index.cgi?mode=al2&namber=16657
の掲示板ネタ。T-SQLな日付処理だけど、実はSQLCLRのユーザー関数で組むと一瞬なんじゃなかろーかとも思ってしまったですよ。日付の計算や文字列変換なんかは、.NetFrameworkの関数が強力だからそれを使わない手はないと思うの。

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports System.Globalization

Partial Public Class UserDefinedFunctions
  <Microsoft.SqlServer.Server.SqlFunction()> _
  Public Shared Function GetNextMonth(ByVal pDateYM As String) As SqlString
    Dim wRetDateYM As New DateTime
    If DateTime.TryParseExact(pDateYM, "yyyyMM", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, wRetDateYM) = False Then
      Return New SqlString.Null
    Else
      Return New SqlString(wRetDateYM.AddMonths(1).ToString("yyyyMM"))
    End If
  End Function
End Class

で、これで、コンパイルして、アセンブリを配置すると、

select dbo.GetNextMonth('200712')  as Ret

Ret
------------------------
200801

(1 行処理されました)

select dbo.GetNextMonth('200713') as Ret

Ret
------------------------

(1 行処理されました)

こんなカンジ。

で、うふふ、こんなのめっけた♪ SQLCLRでHelloWorld!

http://www.atmarkit.co.jp/fdotnet/special/sqlclr02/sqlclr02_01.html

SQLCLRのさらっとした概略はこちらに
http://www.microsoft.com/japan/msdn/sqlserver/sql2005/sqlclrguidance.aspx

投稿日時 : 2008年4月9日 21:59

コメント

# re: おぎわらさんのエントリ、面白そうだったんで、VBでも書いてみた 2008/04/10 1:55 Mr.T
CLRには手を出してないorz

というか、どうして日付を文字型にするんだろという疑問はまだ解消できてねーっす。


# re: おぎわらさんのエントリ、面白そうだったんで、VBでも書いてみた 2008/04/10 20:14 片桐
サンプル文字型にしたけど、数字型でも良いと思うw<そうじゃないw

結局、日付型、つまりシリアル値でもつ文化が日本にはないってのもあるんじゃないかなぁなんて思うデスよ。
あくまでも、見た目。だって、昔の暦って数字使ってないときもあったんだから(笑)

# Oakley Sunglasses Cheap 2013/03/23 19:23 http://cancunconvenciones.com/oakley-sunglasses-ch
I can't afford to go to a restaurant every day.Which would you prefer? I'm home.There is a bridge over the river.It really takes time.Is there any sugar in the bottle? Is there any sugar in the bottle? Not bad.Allow me.That is my idea about friendship

Post Feedback

タイトル
名前
Url:
コメント