Results 1 to 3 of 3

Thread: [RESOLVED] Creating a Date in SQL Server?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [RESOLVED] Creating a Date in SQL Server?

    I need to create a Date Field to return to a VB.Net app based on the current month/year, however the day needs to be the 1st day of the month. Here is what I have and it's not working.

    Code:
    Convert(DateTime, Month(GetDate()) + '/1/' + Year(GetDate()), 101) as DayOne
    How would I do this? I can't find any examples online.
    Blake

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Creating a Date in SQL Server?

    Month and Year return numbers. You can't add a number and a string. You need a string, so convert the numbers to strings. You can then concatenate all the strings and then convert the result to a datetime.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Creating a Date in SQL Server?

    Thanks!
    Blake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width